【问题标题】:duplication in dropdown item ASP.net下拉项 ASP.net 中的重复项
【发布时间】:2021-10-13 22:09:08
【问题描述】:

我在 ASP.NET 12 中遇到 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();
}

【问题讨论】:

标签: c# asp.net webforms dropdown


【解决方案1】:

按照 cmets 的建议:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // your above page load code goes here
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多