zoukankan      html  css  js  c++  java
  • 从xml文件中绑定数据到DropDownList控件上

    参考了2篇文章:

    http://www.cnblogs.com/JuneZhang/archive/2010/11/23/1885671.html

    http://blog.sina.com.cn/s/blog_4d4d3ade01000apj.html

        private string _RootPath;
                /// <summary>   
                /// 系统的根目录   
                /// </summary>   
                public string RootPath
                {
                    get
                    {
    
                        _RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath).ToLower();//当前的绝对路径              
                        if (_RootPath.Length == 1)
                        {
                            _RootPath = "";
                        }
                        return _RootPath;
                    }
                }
      private void BindDepConfig()
            {
                dropdownDep.DataSource = createDataSource();
                dropdownDep.DataTextField = "depTextField";
                dropdownDep.DataValueField = "depValueField";
                dropdownDep.DataBind();
    
            }
             
                private ICollection createDataSource()
    
                {
                    
                      DataTable dt = new DataTable();
     
                      //define the columns of the table
                      dt.Columns.Add("depTextField",typeof(string));
                      dt.Columns.Add("depValueField",typeof(string));
     
                      //read the content of the xml file into a DataSet
                      DataSet lanDS = new DataSet();
                      string filePath = RootPath + "/Data/Xml/ThridDepConfig.xml";
                      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;
                }
    <?xml version="1.0" encoding="utf-8"?>
     
    <depTypes>
      <dep>
        <depValueField>电教处</depValueField>
        <depTextField>电教处</depTextField>
      </dep>
      <dep>
        <depValueField>总务处</depValueField>
        <depTextField>总务处</depTextField>
      </dep>
      <dep>
        <depValueField>后勤处</depValueField>
        <depTextField>后勤处</depTextField>
      </dep>
    </depTypes>
  • 相关阅读:
    day 22 反射,双下方法
    day 21 封装,多态,类的其他属性
    day 20 类与类之间的关系,继承2
    day 19 类的名称空间,组合,派生
    day 18 类,对象
    day 17 re模块
    注意NULL
    SQL_DISTINCT
    重载赋值运算符
    随机序列问题
  • 原文地址:https://www.cnblogs.com/wenjie/p/3335037.html
Copyright © 2011-2022 走看看