Click here to Skip to main content
14,736,900 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends, am working on gridview and am using bound fields and sqldatasource to display the data.

in this i have one coulmn with name Creation Date.

<asp:BoundField DataField="CreationDate" HeaderText="CreationDate"
                            SortExpression="CreationDate"/>



But it is displaying date as 1/13/2013 12:00:00 AM.

here i want to display only date as 13/1/2013

Please help me and solve this.

Thanks.
Posted
Comments
Shanu2rick 16-Jan-13 5:22am
   
use the OnRowBound event to change the format of your date

Try this:
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:d}" htmlencode="false" />


For other formats look into below link:
how-to-set-date-format-in-gridview.html[^]
Date-Formatting-in-CSharp[^]
   
v2
Comments
Ubaid ur Rahman IT 16-Jan-13 5:26am
   
Thanks Vani
Vani Kulkarni 16-Jan-13 5:29am
   
Welcome! :-)
You can use BoundField.DataFormatString Property[^] to specify the display format for the value of the field.
<asp:boundfield datafield="CreationDate" headertext="CreationDate" sortexpression="CreationDate" dataformatstring="{0:dd/MM/yyyy}"  />
   
v2
Comments
Ubaid ur Rahman IT 16-Jan-13 5:26am
   
Thankyou
__TR__ 16-Jan-13 5:28am
   
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900