【问题标题】:How to remove time in my DataGridView column如何删除我的 DataGridView 列中的时间
【发布时间】:2018-10-29 06:26:18
【问题描述】:

您好,我正在创建一个GridView 数据以在 Web 应用程序中显示我的 CSV。我有一个来自数据表的gridviewGoods Reciept 日期为DateTime。这里的问题是如何从我的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 日期没有时间。

【问题讨论】:

标签: c# asp.net datetime


【解决方案1】:

您应该尝试将formatting your date 转换为类似dd-MM-yyyy 格式的字符串:

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

【讨论】:

    【解决方案2】:

    如何将其转换为 .NET DateTime,然后使用 Date 属性。像这样的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多