新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
使用asp.net怎么將XML數(shù)據(jù)綁定到DropDownList-創(chuàng)新互聯(lián)
本篇文章為大家展示了使用asp.net怎么將XML數(shù)據(jù)綁定到DropDownList,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
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 日語(yǔ)
上述內(nèi)容就是使用asp.net怎么將XML數(shù)據(jù)綁定到DropDownList,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前標(biāo)題:使用asp.net怎么將XML數(shù)據(jù)綁定到DropDownList-創(chuàng)新互聯(lián)
本文地址:http://fisionsoft.com.cn/article/dsesog.html