Populating text box with string date-time without the time
I have a table that holds a datetime field. I have put that into a datakey
and on pageload and select from gridview it will populate the textbox with
the datetime from the table in the database. I do not want the time. In
the grid view I have already gotten rid of the time but when i populate
the textbox I can not get rid of it. Any suggestions? here is my code: (I
need both the PurchaseDate and WarrantyDate to show only the date without
the time)
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();
}
In the gridview I did this to change the datetime to only the date:
<asp:BoundField DataField="PurchaseDate" HeaderText="Purchase Date"
InsertVisible="False" ReadOnly="True" DataFormatString="{0:d}" />
<asp:BoundField DataField="WarrantyExpDate" HeaderText="Warranty Date"
InsertVisible="False" ReadOnly="True" DataFormatString="{0:d}" />
No comments:
Post a Comment