Click here to Skip to main content
12,699,489 members (33,673 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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 1: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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 9 Aug 2013
Copyright © CodeProject, 1999-2017
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