Click here to Skip to main content
11,483,586 members (67,879 online)
Rate this: bad
good
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 16-Jan-13 0:16am
Comments
Shanu2rick at 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 at 16-Jan-13 5:26am
   
Thanks Vani
Vani Kulkarni at 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 at 16-Jan-13 5:26am
   
Thankyou
__TR__ at 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
0 Sergey Alexandrovich Kryukov 305
1 Frankie-C 195
2 Raje_ 155
3 OriginalGriff 142
4 Abhipal Singh 108
0 Sergey Alexandrovich Kryukov 8,444
1 OriginalGriff 7,903
2 Sascha Lefèvre 3,114
3 Maciej Los 2,521
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
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