无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了asp.net实现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
<"1.0"encoding="utf-8""color: #800000">PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson在线格式化XML/在线压缩XML:
http://tools.jb51.net/code/xmlformatXML在线压缩/格式化工具:
http://tools.jb51.net/code/xml_format_compressXML代码在线格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net操作XML技巧总结》、《asp.net操作json技巧总结》、《asp.net字符串操作技巧汇总》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 赞多《序章》[FLAC/分轨][129.13MB]
- 群星《完美的她 影视原声带》[320K/MP3][51.98MB]
- 群星《完美的她 影视原声带》[FLAC/分轨][141.05MB]
- 山风点伙.1997-深藏不露【立得】【WAV+CUE】
- 李幸倪.2018-First.Of.All.Live.Concert.3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 群星《你就在我身边 电影原声专辑》[320K/MP3][26.68MB]
- 群星《你就在我身边 电影原声专辑》[FLAC/分轨][70.27MB]
- 班得瑞原装进口《20周年精选集》1CD[APE/CUE分轨][303MB]
- 群星.2009-NOON.D.广东.2CD【新世纪】【WAV+CUE】
- 洪卓立.2012-GROWN.UP【英皇娱乐】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 金佩姗.1997-喜新恋旧【现代派】【WAV+CUE】