Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
Hello All,
I want to change the format of the date field binded in a grid based upon the language selection.
e.g: If the language is english/ USEnglish then the format should be "dd/MM/yyyy" and if the language is something else then the date format should be "MM/dd/yyyy". Please suggest me how to do this.
Posted 28-Feb-13 0:43am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

HI all,
I found the solution as follows:
aspx grid code:
<asp:TemplateField HeaderText="" ControlStyle-Width="20px" ItemStyle-BackColor="#FFFFFF" ItemStyle-Font-Names="Verdana">
                            <asp:Label ID="lblDateTimeSent" runat="server" Text='<%# FormatDate(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "DateTimeSent"))) %>' style="text-align:center;"></asp:Label>
Code behind code:
public string FormatDate(DateTime input)
            //String languageID = Convert.ToString(Session["LanguageId"]);
            if (languageId == int.Parse(System.Configuration.ConfigurationManager.AppSettings["DefaultLanguageID"]))
                return string.Format("{0:MM/dd/yy}", input);
                return string.Format("{0:dd/MM/yy}", input);
This above solution will be helpful to all but this will not work with the bound field. If there are bound fields then we need to use the item template instead.

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

  Print Answers RSS
0 OriginalGriff 377
1 Nirav Prabtani 284
2 Richard Deeming 190
3 _Amy 170
4 Mehdi Gholam 140
0 Nirav Prabtani 265
1 OriginalGriff 177
2 _Amy 170
3 Mehdi Gholam 105
4 Maciej Los 90

Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 9 Aug 2013
Copyright © CodeProject, 1999-2014
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