亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net實(shí)現(xiàn)XML文件讀取數(shù)據(jù)綁定到DropDownList的方法

 更新時(shí)間:2017年02月14日 11:48:49   作者:念時(shí)  
這篇文章主要介紹了asp.net實(shí)現(xiàn)XML文件讀取數(shù)據(jù)綁定到DropDownList的方法,結(jié)合實(shí)例形式分析了asp.net針對(duì)xml文件操作及DropDownList控件的使用技巧,需要的朋友可以參考下

本文實(shí)例講述了asp.net實(shí)現(xiàn)XML文件讀取數(shù)據(jù)綁定到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>日語(yǔ)</languageTextField>
  </language>
</languageTypes>

PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:

在線XML/JSON互相轉(zhuǎn)換工具:
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

更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net操作XML技巧總結(jié)》、《asp.net操作json技巧總結(jié)》、《asp.net字符串操作技巧匯總》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論