ASP.NET - DataFormatString problem
Asked By Sharad Chandra on 05-Sep-11 03:36 AM
hi friends
i got dataformatstring problem for date in gridview
i using DataFormatString="{0:dd/MM/yyyy}",
but it display like dd-MM-yyyy, where is problem,
dipa ahuja replied to Sharad Chandra on 05-Sep-11 03:43 AM
Untitled document
► For bound field
<asp:BoundField DataField="bdate" DataFormatString="{0:dd/MM/YYYY}" HeaderText="bdate"
SortExpression="bdate" />
► for template Field
<asp:TemplateField HeaderText="imageurl">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ttyme", "{0:MMMM d, yyyy}"%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Reena Jain replied to Sharad Chandra on 05-Sep-11 03:45 AM
Hi,
for the
BoundColumn to display a short date.
<asp:label runat="server" DataTextField="date"
HeaderText="date" DataNavigateUrlFields="date" DataTextFormatString="{0:dd-MM-yyyy}" DataNavigateUrlFormatString="defalut.aspx?date={0}"
ControlStyle-Width="120px" />
hope this will help you
Rohan Dave replied to Sharad Chandra on 05-Sep-11 03:48 AM
try by below ...
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate" DataFormatString="{0:d}" HtmlEncode=false />
see the red color bold highlighted part.. you just need to pass " d " to display date and make sure to set HtmlEncode = false...
Sharad Chandra replied to dipa ahuja on 05-Sep-11 03:50 AM
i am using same but date shows like dd-MM-yyyy in gridview
dipa ahuja replied to Sharad Chandra on 05-Sep-11 03:53 AM
Are you getting date in the gridview? and check your table contains the correct date Value..
Sharad Chandra replied to Rohan Dave on 05-Sep-11 03:55 AM
i already using DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false",
but data in gridview show like dd-MM-yyyy
Sharad Chandra replied to dipa ahuja on 05-Sep-11 04:00 AM
ya date shows in gridview with changed format,
and table contain data like MM/dd/yyyy
dipa ahuja replied to Sharad Chandra on 05-Sep-11 04:13 AM
so you want the same format like in table or you want any other format..
the code i posted and which you have used is correct.
But i am not getting what you want, you want same format in table or you want any other format?
if you want other format then DataFormatString property is correct , bt don't knw why you are not getting result
pete rainbow replied to Sharad Chandra on 05-Sep-11 04:18 AM
The "/" custom format specifier represents the date separator, which s
used to differentiate years, months, and days. The appropriate localized
date separator is retrieved from the http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.dateseparator.aspx property of the current or specified culture.
so i would imagine you have - as your separator on the client
if you really want to override this then change to escape it
DataFormatString="{0:dd\/MM\/yyyy}",
Sharad Chandra replied to dipa ahuja on 05-Sep-11 05:04 AM
i want any date format
actually this is working in my PC but i run same in other PC it work with changed format
I am also not understand why it happen
Anoop S replied to Sharad Chandra on 05-Sep-11 05:35 AM
Use like this way
DateTime time = DateTime.Now;
string format = "MM/dd/yyyy";
label1.Text = time.ToString(format);
it will show
05/09/2011