从xml文件中绑定数据到DropDownList控件上
2013-09-23 16:11
736 查看
参考了2篇文章:
/article/4967724.html
http://blog.sina.com.cn/s/blog_4d4d3ade01000apj.html
/article/4967724.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>
相关文章推荐
- Demo: Dictionary>> 泛型读取XML文件数据作为数据源(DataSource)绑定到DropDownList控件 定义个一个公用类
- 数据绑定技术_单值数据绑定示例;将 DataTable,DataSet,DataView,DataReader 绑定到 DataGrid 控件示例;DataBinder.Eval;数组的值赋给ListBox1;Hashtable 绑定到;RadioButtonList;将XML 文件做为数据源绑定到控件
- 用DropDownList控件绑定XML数据实现省市区三级联动
- 从XML文件中读取数据绑定到DropDownList
- 转载--从XML文件中读取数据绑定到DropDownList
- 转载--从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList-.Net编程教程
- 从XML文件中读取数据绑定到DropDownList
- 本文介绍了如何从XML文件中读取数据绑定到DropDownList。
- 用DropDownList控件绑定XML数据实现省市区三级联动
- 如何从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 数据绑定技术—将 XML 文件做为数据源绑定到控件
- 用DropDownList控件绑定XML数据实现省市区三级联动
- 从XML文件中读取数据绑定到DropDownList
- XML文件读取数据绑定到DropDownList
- ASP.NET中DropDownList控件的数据绑定的C#语言描述
- 数据绑定控件和XmlDataSource控件结合使用,通过后台绑定Xml数据片段遇到的问题
- asp.net Xml绑定到数据控件的具体实现
- 控件数据绑定--Xml做数据源