In an aspx page I am binding the labels like this:
<asp:TemplateField HeaderText="Date of Joining">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("date_of_joining") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Paid Priviledge Date">
<ItemTemplate>
<asp:Label ID="Label8" runat="server"
Text='<%# Eval("paid_priviledge_date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
And in the code behind I'm binding the grid view like this :(minimum code is given)
GridView1.DataSource = dt2;
GridView1.DataBind();
But the gridview columns show the date like this :
4/12/2011 12:00:00 AM
4/4/2011 12:00:00 AM
Please suggest how to remove the time stamp part and to display only the date part.
I know how to do this by formatting using ToString and SubString. But I am not able to do this in gridview.
You have to Create a BoundField, set its properties including the property dataformatstring which you can use to set format of the field appear in the GridView, and add it to the GridView control.
in ASP.Net. The HTML Markup consists of an ASP.Net Repeater control rendered as an HTML Table with three columns. The DateTime field value is converted to dd/MM/yyyy by passing an additional parameter i.e. {0:dd/MM/yyyy} in order to format and display the DateTime field value in dd/MM/yyyy format.
The long date option adds the day of the week and writes out the month. So 1/1/19 will display as Tuesday, January 1, 2019. The date will display in the format you choose, no matter how you enter it. If you type "1/1/19" into a cell with the long date format, Excel will change it to the expanded date.
You can specify format strings for the eval statement:
Eval("date_of_joining", "{0:dd/MM/yyyy}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With