如何根据语言选择更改网格中日期的格式 [英] How to change the format of the date in a grid based upon language selection

查看:87
本文介绍了如何根据语言选择更改网格中日期的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我想根据语言选择更改网格中绑定的日期字段的格式。



例如:如果语言是英语/ USEnglish,则格式应为dd / MM / yyyy,如果语言不是其他语言,则日期格式应为MM / dd / yyyy。请建议我怎么做。



谢谢

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.

Thanks

推荐答案

HI all,



我找到的解决方案如下:



aspx网格代码:

HI all,

I found the solution as follows:

aspx grid code:
<asp:TemplateField HeaderText="" ControlStyle-Width="20px" ItemStyle-BackColor="#FFFFFF" ItemStyle-Font-Names="Verdana">
                            
                            <ItemTemplate>
                            <asp:Label ID="lblDateTimeSent" runat="server" Text='<%# FormatDate(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "DateTimeSent"))) %>' style="text-align:center;"></asp:Label>
                            </ItemTemplate>
                            </asp:TemplateField>





代码代码:



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);
            }
            else
            {
                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.

Thanks


这篇关于如何根据语言选择更改网格中日期的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆