zoukankan      html  css  js  c++  java
  • DropDownList绑定Xml数据的实现

    1 、绑定DropDownList:

        ddl_language.DataSource = createDataSource();
        ddl_language.DataTextField = "languageTextField";
        ddl_language.DataValueField = "languageValueField";
        ddl_language.DataBind();

    2、上面用到的createDataSource()方法: 

               private ICollection createDataSource()
                {
                      //create a data table to store the data for the ddl_langauge control
                      DataTable dt = new DataTable();
     
                      //define the columns of the table
                      dt.Columns.Add("languageTextField",typeof(string));
                      dt.Columns.Add("languageValueField",typeof(string));
     
                      //read the content of the xml file into a DataSet
                      DataSet lanDS = new DataSet();
                      string filePath = ConfigurationSettings.AppSettings["LanguageXmlFile"];
                      lanDS.ReadXml(filePath);
     
                      if(lanDS.Tables.Count > 0)
                      {
                                  foreach(DataRow copyRow in lanDS.Tables[0].Rows)
                                  {
                                        dt.ImportRow(copyRow);
                                }
                      }
     
                      DataView dv = new DataView(dt);
     
                      return dv;
                }
    3、Web.config
     
            <appSettings>
                <!--The file path for the language type xml file-->
                <addkey="LanguageXmlFile"value="d:\Rhombussolution\Rhombus2\Languages.xml"/>
    </appSettings>

     4、Languages.xml 

    <?xmlversion="1.0"encoding="utf-8"?>
    <languageTypes>
       <language>
          <languageValueField>en-US</languageValueField>
          <languageTextField>English</languageTextField>
       </language>
       <language>
          <languageValueField>zh-CN</languageValueField>
          <languageTextField>中文</languageTextField>
       </language>
       <language>
          <languageValueField>ja-JP</languageValueField>
          <languageTextField>日语</languageTextField>
       </language>
    </languageTypes>
  • 相关阅读:
    VB运算符总结
    动态实现树形菜单
    使用C#开发ActiveX控件
    jquery+ajax加载xml文件到页面
    C#序列化与反序列化
    jquery之ajax——全局事件引用方式以及各个事件(全局/局部)执行顺序
    SerialPort实现对串口COM的操作(有些纠结)
    jquery+ajax+C#实现无刷新操作数据库数据
    超过一百多个Web2.0在线生成器
    asp.net URL Rewriter 问题
  • 原文地址:https://www.cnblogs.com/fumj/p/2605604.html
Copyright © 2011-2022 走看看