更新的时候提示错误如下:
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 81:     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
行 82:     {
行 83:         string id = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班级号")).Text;行 84:         string name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班级名")).Text;
行 85:         string ren = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班主任")).Text;
 
更新代码如下:
  protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string id = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班级号")).Text;
        string name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班级名")).Text;
        string ren = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("班主任")).Text;
         string conn = ConfigurationSettings.AppSettings["mc"];
        SqlConnection myconn = new SqlConnection(conn);
       
        myconn.Open();
        string sqlstr="updata bje set 班级号="+id+",班级名="+name+",班主任="+ren+" ";
        SqlCommand mycom = new SqlCommand(sqlstr, myconn);
        mycom.ExecuteNonQuery();
        myconn.Close();
        GridView1.EditIndex=-1;
        GridView1.DataBind();
    }
请问哪里出问题 了,麻烦各位帮一下忙,谢谢

解决方案 »

  1.   

    GridView1.Rows[e.RowIndex].FindControl("班级号")这样是获取模板列里的控件的
    你换成这样试试
    this.GridView1.Rows[e.RowIndex].Cells[列索].FindControl()
      

  2.   

    这样也出现错误
    编译器错误信息: CS1501: “FindControl”方法没有采用“0”个参数的重载源错误: 行 81:     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    行 82:     {
    行 83:         string id = GridView1.Rows[e.RowIndex].Cells[0].FindControl();行 84: 
    行 85:         string name = GridView1.Rows[e.RowIndex].Cells[1].FindControl();
     
      

  3.   

    string id = this.GridView1.Rows[e.RowIndex].Cells[列索].FindControl("控件名").Text
      

  4.   

    我看过视频,好像不是用的FindControl,而是用的Control