• ASP的可本地化下拉列表。NET 2.0


    下载源码- 10.88 KB 介绍 代码展示了一种简单的绑定基于ListItem的控件的方法,比如下拉菜单到一个资源文件。 Background  其思想是将数据存储为XML格式,而不是名称值集合,并使用XMLDataSource对象将其绑定到。net控件。, 使用Code , 我添加了一个字符串资源“MyCountryList”,

      

    它包含了用于下拉控件的XML数据。, Resource.en-US.resx 隐藏,复制Code

    <countries>
      <countrytext="Pakistan"value="PK"/>
      <countrytext="Iran"value="IR"/>
      <countrytext="Afghanistan"value="AF"/>
    </countries>

    Resource.es-MX.resx 隐藏,复制Code

    <countries>
      <countrytext="Pakistan-Spanish"value="PK"/>
      <countrytext="Iran-Spanish"value="IR"/>
      <countrytext="Afghanistan-Spanish"value="AF"/>
    </countries>

    default . aspx 隐藏,复制Code

    <formid="form1"runat="server">
            <asp:HyperLinkID="HyperLink1"runat="server"NavigateUrl="~/Default.aspx?lang=esp">Esp</asp:HyperLink>
              
            <asp:HyperLinkID="HyperLink2"runat="server"NavigateUrl="~/Default.aspx?lang=eng">Eng</asp:HyperLink><br/>
            <br/>
            <asp:LocalizeID="Localize1"runat="server"Text="<%$ Resources:Resource, Greeting%>"></asp:Localize>
            <br/>
            <asp:XmlDataSourceID="XmlDataSource1"runat="server"></asp:XmlDataSource>
            <asp:DropDownListID="DropDownList1"runat="server">
            </asp:DropDownList>
    </form>

    Default.aspx.cs 隐藏,收缩,复制Code

    protected void Page_Load(object sender, EventArgs e)
        {
            // loading xml from resource file into xmldatasource object
            XmlDataSource1.Data = Resources.Resource.MyCountryList;
            XmlDataSource1.EnableCaching = false;
            XmlDataSource1.DataBind();        
    
            DropDownList1.DataSourceID = "XmlDataSource1";
            DropDownList1.DataTextField = "text";
            DropDownList1.DataValueField = "value";
            DropDownList1.DataBind();
        }
       //The setting up the culture
        protected override void InitializeCulture()
        {
            string lang = "en-US";
            if (Request.QueryString["lang"] != null)
            {
                switch (Request.QueryString["lang"])
                {
                    case "esp":
                        lang = "es-MX";
                        break;
                    case "eng":
                        lang = "en-US";
                        break;
                }
            }
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(lang);
            System.Threading.Thread.CurrentThread.CurrentCulture = ci;
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            base.InitializeCulture();
        } 

    斜体显示了绑定到资源文件的两种方法。您还可以下载本文附带的源代码。 历史 2009年1月1日:初任 本文转载于:http://www.diyabc.com/frontweb/news330.html

  • 相关阅读:
    mock中测试private方法,不是mock
    PHP检测每一段代码执行时间
    Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
    php返回HTTP状态码
    PHP获取今天、昨天、明天的日期
    memcache及其telnet命令使用详解
    PHP的json_encode中文被转码的问题
    PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明
    php pack()函数详解与示例
    socket编程原理
  • 原文地址:https://www.cnblogs.com/Dincat/p/13437583.html
Copyright © 2020-2023  润新知