Click here to Skip to main content
12,403,811 members (69,524 online)
Rate this:
 
Please Sign up or sign in to vote.
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 15-Jan-13 23:16pm
Comments
Shanu2rick 16-Jan-13 5:22am
   
use the OnRowBound event to change the format of your date
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
v2
Comments
Ubaid ur Rahman IT 16-Jan-13 5:26am
   
Thanks Vani
Vani Kulkarni 16-Jan-13 5:29am
   
Welcome! :-)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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}"  />
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100