欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【从XML文件中读取数据绑定到DropDownList】,下面是详细的分享!
从XML文件中读取数据绑定到DropDownList
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"?> |
以上所分享的是关于从XML文件中读取数据绑定到DropDownList,下面是编辑为你推荐的有价值的用户互动:
相关问题:用c#写个省市区三联动的winform程序,从xml文件中...
答:这是代码参考一下,另有附件. using System;using System.Collections.Generic;using System.ComponentModel;using Syste... >>详细
相关问题:C#中Dropdownlist如何读取数据库绑定并且联动
答:图书类型: 计算机 文学 书架: 右A-1 右B-1 左A-1 左B-1 这是我的源代码 为什么我的不是这样 Dropdownlist的属性 AutoPostBack 和这个没有关系吧 把你后台代码 拿出来看看 >>详细
相关问题:C语言 如何读取xml文件中的数据并存入一个结构体中
答:利用com、 用xml的dll就可以了,不多说了,具体再不懂再问我把。 我工作也有解析xml文件的 呵呵 >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
