Friday, April 24, 2009

Format dates in a Gridview column



Some time we want that the dates should be shown in particular manner like "dd/mm/yyyyy" but we get stuck in what will be the formatting in Grid view
so for solving this type of problem we place a grid view in the asp.net web page and in the source codes i.e. HTML we have to insert this as a column To format a gridview column to display dates properly , two properties needs to be changed, the DateFormatString property and the HTML encode property. After setting the DateFormatString the HTMLEncode property should be set to false. For Example :

<asp:BoundField DataField="RegistrationDate" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Date"
HtmlEncode="False" SortExpression="RegistrationDate" />

the above code will display the desired output