asp.net實(shí)現(xiàn)XML文件讀取數(shù)據(jù)綁定到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ì)有所幫助。
- asp.net 讀取xml文件里面的內(nèi)容,綁定到dropdownlist中
- asp.net使用DataSet的ReadXml讀取XML文件及Stream流的方法
- ASP.NET讀取XML文件4種方法分析
- Javascript+XMLHttpRequest+asp.net無(wú)刷新讀取數(shù)據(jù)庫(kù)數(shù)據(jù)
- ASP.NET中讀取XML文件信息的4種方法與示例代碼
- ASP.NET MVC DropDownList數(shù)據(jù)綁定及使用詳解
- ASP.NET MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法
- ASP.NET Ajax級(jí)聯(lián)DropDownList實(shí)現(xiàn)代碼
- asp.net DropDownList自定義控件,讓你的分類更清晰
- ASP.NET DropDownList控件的使用方法
- (asp.net c#)DropDownList綁定后顯示對(duì)應(yīng)的項(xiàng)的兩種方法
- ASP.NET筆記之 ListView 與 DropDownList的使用
相關(guān)文章
asp.net 網(wǎng)頁(yè)動(dòng)態(tài)查詢條件的實(shí)現(xiàn)
最近有一個(gè)需求,會(huì)在 mongodb 中插入各種類型的數(shù)據(jù),算是記錄業(yè)務(wù)日志的數(shù)據(jù)庫(kù)吧。因?yàn)闃I(yè)務(wù)對(duì)象類型都不同,所以插入的數(shù)據(jù)格式也完全不同2012-10-10
ASP.NET使用gridview獲取當(dāng)前行的索引值
這篇文章主要介紹了ASP.NET使用gridview獲取當(dāng)前行的索引值的方法匯總,有需要的小伙伴可以參考下。2015-06-06
asp.net 學(xué)習(xí)之路 項(xiàng)目整體框架簡(jiǎn)單的搭建
最近剛學(xué)了些關(guān)于asp.net mvc方面的知識(shí),于是了要拿個(gè)小項(xiàng)目來(lái)練練手,提高下自己的code能力跟思維能力2012-12-12
ASP.NET(C#) 定時(shí)執(zhí)行一段代碼
在Global.asax啟動(dòng)一條線程就ok了,下面是啟動(dòng)線程定時(shí)寫(xiě)文件的例子.2009-11-11
ASP.NET Core 2.0 帶初始參數(shù)的中間件問(wèn)題及解決方法
這篇文章主要介紹了ASP.NET Core 2.0 帶初始參數(shù)的中間件問(wèn)題及解決方法,需要的朋友可以參考下2017-10-10

