how to format date time at time of binding in gridview
I have a field of type DateTime which is bound in gridview.
Now, i would liketo display only date from this field, and not time. Date Should be in1/1/0001
this format.
I am using DotnetNuke
My code is as follows
开发者_JS百科<asp:TemplateField HeaderText="Created On">
<itemtemplate>
<%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","0:dd/MM/yyyy}")%>
</itemtemplate>
</asp:TemplateField>`.
I have tried the format that is used but its output is like this 1/1/0001 12:00:00 AM.
What shall I do?
You are missing an opening angular brace {
. Try this.
<asp:TemplateField HeaderText="Created On">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Alb_Created_Date", "{0:dd/MM/yyyy}")%>
</itemtemplate>
</asp:TemplateField>
In your code you have given wrong syntax in the format, and due to which its not formatting correctly and giving out the data base value itself. Please, format it as below.
<%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","{0:dd/MM/yyyy}")%>
精彩评论