下拉项重复 ASP.net
duplication in dropdown item ASP.net
我在 ASP.NET 1, 2 中的 DropDownList 有问题。
每次我 select 一个项目,列表中的项目都会重复 3。
只有 selection 的第一次看起来不错。
我的代码 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();
}
如评论中所建议:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// your above page load code goes here
}
}
我在 ASP.NET 1, 2 中的 DropDownList 有问题。
每次我 select 一个项目,列表中的项目都会重复 3。
只有 selection 的第一次看起来不错。
我的代码 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();
}
如评论中所建议:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// your above page load code goes here
}
}