protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1");
Updateuser.ROLEID = Convert.ToInt16(ddl.SelectedValue.ToString());这是后台代码,后面方问ddl的值的语名出错,我看了一下局部变量,说ddl是NULL,应该是没找到下拉框的控件,不知道错出在哪,请高手指点
DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].Cells[3].FindControl("DropDownList1");
我指定了单元也不行
{DropDownList1.DataBind();
}
还有你是在那个事件里要获取DropDownList
要是在RowDataBound这个事件下
就用e.Row.Cells["0"].FindControl("DropDownList1") as DropDownList
要是在RowDeleting和RowUpdating事件下
就用this.GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList
GridView1_RowUpdating这个事件里调用,你的方法我试过了,用单步运行,局部变量ddl是NULL,郁闷啊!高手们快解救哥们一下吧
设断点,调试,找到调试里面的即时
输入
GridView1.Rows[e.RowIndex].Cells[3].controls
看看 这里面控件都是啥,哪个是你想要的GridView1.Rows[e.RowIndex].Cells[3].controls[0]
GridView1.Rows[e.RowIndex].Cells[3].controls[1]
GridView1.Rows[e.RowIndex].Cells[3].controls[2]一点点试试看