vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, April 25, 2012

Format Date and time in grid view


Introduction:

In this article we will see to display date and time in correct format in grid view.

In many cases when we display date or time in grid view its show either date with time or only time. But, our need is to follow some standard format to display.

In that case we need to follow some code before binding grid view…

In two ways we used to binding data in grid view,using either template field or bound field.

Template field:
For Display time
<asp:TemplateField HeaderText="Date">
 <ItemTemplate>
 <%#Eval("Date", "{0:HH:mm:ss}")%>
 </ItemTemplate>
</asp:TemplateField>

For Date
<asp:TemplateField HeaderText="Date">
 <ItemTemplate>
 <%#Eval("Date", "{0:dd-MM-yyyy}")%>
</ItemTemplate>
</asp:TemplateField>

Bound field
<asp:BoundField HeaderText ="date2" DataField =" Date" DataFormatString ="{0:t}" />
For date:
<asp:BoundField HeaderText ="date2" DataField ="Date" DataFormatString ="{0:d}" />

I hope you like this article….

0 comments:

Post a Comment