导读:
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
本文介绍了一种使用C#语言绑定DropDownList的方法。通过创建数据源并读取XML文件中的数据,填充下拉列表的显示文本和值。具体步骤包括定义数据表结构、导入XML文件内容及设置DropDownList的数据字段。
819

被折叠的 条评论
为什么被折叠?



