导读:
1 、绑定DropDownList:
ddl_language.DataSource = createDataSource();
ddl_language.DataTextField = "languageTextField";
ddl_language.DataValueField = "languageValueField";
ddl_language.DataBind(); bbs.bitsCN.com
2、上面用到的createDataSource()方法: bbs.bitsCN.com中国网管论坛
privateICollection createDataSource()
{
//create a data table to store the data for the ddl_langauge control
DataTable dt = newDataTable();
//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 = newDataSet();
stringfilePath = ConfigurationSettings.AppSettings["LanguageXmlFile"];
lanDS.ReadXml(filePath);
if(lanDS.Tables.Count >0)
{
foreach(DataRow copyRow inlanDS.Tables[0].Rows)
{
dt.ImportRow(copyRow);
}
}
DataView dv = newDataView(dt);
returndv;
}
3、Web.config
4、Languages.xml bitsCN~com
本文转自
http://www.bitscn.com/dotnet/xml/200709/109610.html
1 、绑定DropDownList:
ddl_language.DataSource = createDataSource();
ddl_language.DataTextField = "languageTextField";
ddl_language.DataValueField = "languageValueField";
ddl_language.DataBind(); bbs.bitsCN.com
2、上面用到的createDataSource()方法: bbs.bitsCN.com中国网管论坛
privateICollection createDataSource()
{
//create a data table to store the data for the ddl_langauge control
DataTable dt = newDataTable();
//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 = newDataSet();
stringfilePath = ConfigurationSettings.AppSettings["LanguageXmlFile"];
lanDS.ReadXml(filePath);
if(lanDS.Tables.Count >0)
{
foreach(DataRow copyRow inlanDS.Tables[0].Rows)
{
dt.ImportRow(copyRow);
}
}
DataView dv = newDataView(dt);
returndv;
}
3、Web.config
4、Languages.xml bitsCN~com
本文转自
http://www.bitscn.com/dotnet/xml/200709/109610.html