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>
  • 相关阅读:
    CSS之关于clearfix--清除浮动
    C#之垃圾回收
    C#缓存处理
    Asp.Net Mvc4 Ajax提交数据成功弹框后跳转页面
    Asp.Net MVC Ajax
    C#和SQL操作Xml
    领域模型
    Sql操作表字段
    水晶报表行之间切换颜色
    触发器-Trigger
  • 原文地址:https://www.cnblogs.com/wenjie/p/3335037.html
Copyright © 2011-2022 走看看