小编Jos*_*son的帖子

用字符串日期时间填充文本框而没有时间

我有一个包含datetime字段的表.我已将其放入datakey和pageload并从gridview中选择它将使用数据库中表的日期时间填充文本框.我不想要时间.在网格视图中,我已经摆脱了时间,但是当我填充文本框时,我无法摆脱它.有什么建议?这是我的代码:(我需要PurchaseDate和WarrantyDate只显示没有时间的日期)

private void PopulateForm(int index)
    {

        var dataKey = grdvwAssetGrid.DataKeys[index];

        if (dataKey != null)
            AssetId = (int)dataKey["Id"];
        if (dataKey != null)
            LocationId = (int)dataKey["LocationId"];
        if (dataKey != null)
            txtVendor.Text = (string)dataKey["Vendor"];
        if (dataKey != null)
            txtSerialNumber.Text = (string)dataKey["SerialNumber"];
        if (dataKey != null)
            txtDescription.Text = (string)dataKey["Description"];
        if (dataKey != null)
            txtType.Text = (string)dataKey["Type"];
        if (dataKey != null)
            txtPrimaryUser.Text = (string)dataKey["PrimaryUser"];
        if (dataKey != null)
            txtPurchaseDate.Text = dataKey["PurchaseDate"].ToString();
        if (dataKey != null)
            txtWarrantyDate.Text = dataKey["WarrantyExpDate"].ToString();
    }
Run Code Online (Sandbox Code Playgroud)

在gridview中,我这样做是为了将日期时间更改为仅日期:

<asp:BoundField DataField="PurchaseDate" HeaderText="Purchase Date" InsertVisible="False" …
Run Code Online (Sandbox Code Playgroud)

c# asp.net datetime

3
推荐指数
1
解决办法
8215
查看次数

标签 统计

asp.net ×1

c# ×1

datetime ×1