簡體   English   中英

如何在我的DataGridView列中刪除時間

[英]How to remove time in my DataGridView column

嗨,我正在創建一個GridView數據以在Web應用程序中顯示我的CSV。 我有一個gridview從與數據表Goods Reciept日期為DateTime 這里的問題是如何從我的Goods Reciept日期中Goods Reciept

public void Storage00B()
{
    DataTable StorType00B = new DataTable();
    StorType00B.Columns.AddRange(new DataColumn[6] {
        new DataColumn("Material", typeof(string)),
        new DataColumn("Quantity", typeof(float)),
        new DataColumn("Date of Goods Reciept", typeof(DateTime)),
        new DataColumn("Date of Last transaction",typeof(string)),
        new DataColumn("Stock Status", typeof(string)),
        new DataColumn("Storage Type", typeof(string))
    });
    DataTable dt = GetDataTable();
    int B = 0;
    int QB = 0;
    foreach (DataRow row in dt.Rows)
    {
        if (row.Field<String>(5) == "00B\r")
        {
            B++;
            if (row.Field<String>(4) == "Q")
            {
                QB++;
            }
        }
    }

    String StrTyp;



    for (int i = 0; i < dt.Rows.Count; i++)
    {

        StrTyp = dt.Rows[i][5].ToString();
        StorType00B.Rows.Add();
        if (StrTyp == "00B\r")
        {

            StorType00B.Rows[i][0] = dt.Rows[i][0];
            StorType00B.Rows[i][1] = dt.Rows[i][1];
            StorType00B.Rows[i][2] = dt.Rows[i][2];
            StorType00B.Rows[i][3] = dt.Rows[i][3];
            StorType00B.Rows[i][4] = dt.Rows[i][4];
            StorType00B.Rows[i][5] = dt.Rows[i][5];
        }
    }

    Stor_Type00B.Text = "Before IQA Stock Quantity :" + B;
    Q00B.Text = "Total Quality Stock :" + QB;
    StorType00B = StorType00B.Rows.Cast<DataRow>().Where(row => !row.ItemArray.All(field => field is DBNull || string.IsNullOrWhiteSpace(field as string))).CopyToDataTable();
    DataView dv = StorType00B.DefaultView;
    dv.Sort = "Date of Goods Reciept ASC";
    StorageType00B.DataSource = dv;
    StorageType00B.DataBind();

}

這是我目前的結果

圖片

如您所見,我想刪除12:00:00 AM,因為我的Goods Reciept日期沒有時間。

將其轉換為.NET DateTime然后使用Date屬性。 像這樣:

StorType00B.Rows[i][2] = Convert.ToDateTime(dt.Rows[i][2]).Date;

您應該嘗試將日期格式化為類似dd-MM-yyyy的字符串:

StorType00B.Rows[i][2] = Convert.ToDateTime(dt.Rows[i][2]).ToString("dd-MM-yyyy");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM