All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
从XML文件中读取数据绑定到DropDownList_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/23 3:13:28 Browse times: 298 Comment times: 0

从XML文件中读取数据绑定到DropDownList_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

从XML文件中读取数据绑定到DropDownList_[Asp.Net教程]























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
日语










来源:网络


































There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.