【发布时间】:2021-10-13 22:09:08
【问题描述】:
我在 ASP.NET 1、2 中遇到 DropDownList 问题。
每次我选择一个项目时,列表中的项目都会重复3。
仅在第一次选择时看起来不错。
我的代码 C#
protected void Page_Load(object sender, EventArgs e)
{
CRUD myCrud = new CRUD();
string mySql = (@" my query here ");
SqlDataReader dr = myCrud.getDrPassSql(mySql);
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "type";
DropDownList1.DataValueField = "id";
DropDownList1.DataSource = dr;
DropDownList1.DataBind();
CRUD myCrud2 = new CRUD();
string mySql2 = (@" my another query based on the type selected above ");
SqlDataReader dr2 = myCrud2.getDrPassSql(mySql2);
DropDownList3.DataSource = dr2;
DropDownList3.DataTextField = "NameEN";
DropDownList3.DataSource = dr2;
DropDownList3.DataBind();
}
【问题讨论】:
-
只有在
IsPostBack为 false 时才应该填充第一个 DDL。
标签: c# asp.net webforms dropdown