Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何删除我的DataGridView列中的时间_C#_Asp.net_Datetime - Fatal编程技术网

C# 如何删除我的DataGridView列中的时间

C# 如何删除我的DataGridView列中的时间,c#,asp.net,datetime,C#,Asp.net,Datetime,您好,我正在创建一个GridView数据,以在web应用程序中显示我的CSV。我有一个数据表中的gridview,其中goodreceipt日期为DateTime。这里的问题是如何从我的收货日期中删除时间 public void Storage00B() { DataTable StorType00B = new DataTable(); StorType00B.Columns.AddRange(new DataColumn[6] { new DataColumn

您好,我正在创建一个
GridView
数据,以在web应用程序中显示我的CSV。我有一个数据表中的
gridview
,其中
goodreceipt
日期为
DateTime
。这里的问题是如何从我的
收货日期
中删除时间

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();

}
public void Storage00B()
{
DataTable StorType00B=新DataTable();
StorType00B.Columns.AddRange(新数据列[6]{
新数据列(“材料”,类型(字符串)),
新数据列(“数量”,类型(浮动)),
新数据列(“收货日期”,类型(日期时间)),
新数据列(“上次交易日期”,类型(字符串)),
新数据列(“库存状态”,类型(字符串)),
新数据列(“存储类型”,类型(字符串))
});
DataTable dt=GetDataTable();
int B=0;
int QB=0;
foreach(数据行中的数据行)
{
如果(行字段(5)=“00B\r”)
{
B++;
如果(行字段(4)=“Q”)
{
QB++;
}
}
}
字符串StrTyp;
对于(int i=0;i!row.ItemArray.All(field=>field is DBNull | | | string.IsNullOrWhiteSpace(field as string)).CopyToDataTable();
DataView dv=StorType00B.DefaultView;
dv.Sort=“收货日期”;
StorageType00B.DataSource=dv;
StorageType00B.DataBind();
}
这是我目前的结果


如您所见,我想删除12:00:00 AM,因为我的
货物接收日期中没有时间。

如何将其转换为.NET
日期时间,然后使用该属性。大概是这样的:

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

如何将其转换为.NET
DateTime
,然后使用该属性。大概是这样的:

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");
您应该尝试使用类似于
dd-MM-yyyy
格式的字符串:

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

也许可以在datetime值上使用.ToString(“dd/MM/yyyy”)。ToSortDateString()是另一个选项可能重复的是
StorageType00B
GridView实例吗?您能否提供其标记以确保正确设置了
DateFormatString
?也许可以在datetime值上使用.ToString(“dd/MM/yyyy”)。ToSortDateString()是另一个选项可能与
StorageType00B
是GridView实例的副本吗?能否提供其标记以确保正确设置了
DateFormatString