Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2014/1/23 3:13:28
从XML文件中读取数据绑定到DropDownList_[Asp.Net教程]

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


来源:网络







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759