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,应该是没找到下拉框的控件,不知道错出在哪,请高手指点

解决方案 »

  1.   

    DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].Cells[0].FindControl("DropDownList1"); Cells[]不一定是0啊
      

  2.   

    楼上的朋友
    DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].Cells[3].FindControl("DropDownList1"); 
    我指定了单元也不行
      

  3.   

    if(!Page.isPostBack)
    {DropDownList1.DataBind();
    }
      

  4.   

    你的DropDownList是在像模板里还是编辑模板里呀
    还有你是在那个事件里要获取DropDownList
    要是在RowDataBound这个事件下
    就用e.Row.Cells["0"].FindControl("DropDownList1") as DropDownList  
    要是在RowDeleting和RowUpdating事件下
    就用this.GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList
      

  5.   

    楼上的朋友,我的DropDownList是在编辑模板里
    GridView1_RowUpdating这个事件里调用,你的方法我试过了,用单步运行,局部变量ddl是NULL,郁闷啊!高手们快解救哥们一下吧
      

  6.   


    设断点,调试,找到调试里面的即时
    输入
    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]一点点试试看