后台自动添加的服务器控件以及其相应的事件,该事件无法进入、求解决
protected void AddDropList(int pid, int i)
{
DataTable dt = gbll.GetList("ParentID=" + pid).Tables[0];
if (dt.Rows.Count > 0)
{
DropDownList drp = new DropDownList();
drp.ID = "drpGroup" + i;
drp.AutoPostBack = true;
drp.SelectedIndexChanged += new EventHandler(drp_SelectedIndexChanged);
drp.DataSource = dt;
drp.DataTextField = "GrpName";
drp.DataValueField = "ID";
drp.DataBind();
tbProduct.Rows[0].Cells[1].Controls.Add(drp);
AddDropList(Convert.ToInt32(dt.Rows[0]["ID"]), i + 1);
}
}
public void drp_SelectedIndexChanged(object sender, EventArgs e)
{
int id = Convert.ToInt32(drpGroup1.SelectedValue);
int classnum = GetClassNum(id, 2);
DropDownList drp = Page.FindControl("drpGroup" + classnum) as DropDownList;
AddDropList(id, classnum);
}
[解决办法]
你这个自动添加的控件是不是被注销了,一般如果不允许后台事件是因为看不到这个控件了
[解决办法]
你选择一个选项后,没有创建那个下拉列表框,也没有加事件。
所以我说了,你每次都要加下拉列表框和事件。
你设置断点,看看 选择一个选项后,有没有执行过 DropDownList drp = new DropDownList(); 这部分代码,如果没有执行过,那就没有下拉列表框,更没有事件。
因为你自己new出来的控件,是不会自动保存状态的。回发的时候不处理,就会“消失”