栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

asp.net实现XML文件读取数据绑定到DropDownList的方法

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

asp.net实现XML文件读取数据绑定到DropDownList的方法

本文实例讲述了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


  
  


4、Languages.xml



  
   en-US
   English
  
  
   zh-CN
   中文
  
  
   ja-JP
   日语
  


PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

在线格式化XML/在线压缩XML:
http://tools.jb51.net/code/xmlformat

XML在线压缩/格式化工具:
http://tools.jb51.net/code/xml_format_compress

XML代码在线格式化美化工具:
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程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/55770.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号