源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-09-03 12:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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
<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"?>
<languageTypes>
  <language>
   <languageValueField>en-US</languageValueField>
   <languageTextField>English</languageTextField>
  </language>
  <language>
   <languageValueField>zh-CN</languageValueField>
   <languageTextField>中文</languageTextField>
  </language>
  <language>
   <languageValueField>ja-JP</languageValueField>
   <languageTextField>日语</languageTextField>
  </language>
</languageTypes>

[b]PS:这里再为大家提供几款关于xml操作的在线工具供大家参考使用:[/b] [b]在线XML/JSON互相转换工具: [/b][url=http://tools.jb51.net/code/xmljson]http://tools.jb51.net/code/xmljson[/url] [b]在线格式化XML/在线压缩XML: [/b][url=http://tools.jb51.net/code/xmlformat]http://tools.jb51.net/code/xmlformat[/url] [b]XML[/b][b]在线压缩/格式化工具: [/b][url=http://tools.jb51.net/code/xml_format_compress]http://tools.jb51.net/code/xml_format_compress[/url] [b]XML[/b][b]代码在线格式化美化工具: [/b][url=http://tools.jb51.net/code/xmlcodeformat]http://tools.jb51.net/code/xmlcodeformat[/url] 更多关于asp.net相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/660.htm]asp.net操作XML技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/755.htm]asp.net操作json技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/692.htm]asp.net字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/306.htm]asp.net文件操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/535.htm]asp.net ajax技巧总结专题[/url]》及《[url=http://www.1sucai.cn/Special/626.htm]asp.net缓存操作技巧总结[/url]》。 希望本文所述对大家asp.net程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部