相关疑难解决方法(0)

动态添加的DropDownlists不会触发SelectedIndexChanged事件

我看到很多关于这个主题的事情,但我无法找到解决方案.我添加了许多下拉列表与一个事件,但他们没有触发SelectedIndexChanged evet.这是drplist创建者代码:

foreach (var row in cmdSelectCats.ExecuteReader())
{
    var id = row["ProductCategoryID"].ToString();

    var dropDownStatus = new DropDownList {ID = "DrpStatus-" + id};

    dropDownStatus.Items.Add(new ListItem("Aktif", "1"));
    dropDownStatus.Items.Add(new ListItem("Pasif", "2"));

    dropDownStatus.AutoPostBack = true; 
    dropDownStatus.SelectedIndexChanged += Status_SelectedIndexChanged;

    var tableCell = new TableCell();
    tableCell.Controls.Add(dropDownStatus);
    dropDownStatus.SelectedValue = row["ProductCategoryStatusID"].ToString();
    tableRow.Cells.Add(tableCell);
    TblCatList.Rows.Add(tableRow);
}
Run Code Online (Sandbox Code Playgroud)

当然是我的活动:

public void Status_SelectedIndexChanged(object sender, EventArgs e)
{
    //DO SOMETHING
} 
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

c# asp.net

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

c# ×1