最简单的,下拉框绑定数据库字段
给个最简单的绑定的例子,如数据库表就两个字段,一个id,一个name,
下拉框text为name,value值为对应的id,
后台动态绑定,加个“请选择”的空项,就这么简单,别整太复杂的,给个例子就行,OK?
------解决方案--------------------DropDownList1.DataSource = "数据源";
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("-请选择-", ""));
------解决方案-------------------- public static void InitRegionDropDownList(DropDownList ddl)
{
ListItem item = null;
ddl.Items.Clear();
IList<object> items = 通过查询 返回list集合
foreach (var model in items)
{
item = new ListItem(model.CN_CTName, model.ID.ToString());
ddl.Items.Add(item);
}
ddl.Items.Insert(0, new ListItem("请选择", ""));
}
------解决方案--------------------C# code
DataTable dt = CreateDataTable();
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataBind();
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataValueField = "ID";
this.DropDownList1.Items.Insert(0, new ListItem("请选择","0"));
------解决方案--------------------
这个可以
------解决方案--------------------