日期:2014-05-20  浏览次数:20480 次

gridview 中更新
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
  int index = e.RowIndex;
  string ID = GridView1.DataKeys[index].Value.ToString();
  //string title = ((TextBox)(GridView1.Rows[index].Cells[1].Controls[1])).Text.ToString().Trim();
  //string title = ((TextBox)(GridView1.Rows[index].FindControl("title"))).Text.Trim();
  string title = (GridView1.Rows[e.RowIndex].FindControl("title") as TextBox).Text.ToString();
  string zuozhe = ((TextBox)(GridView1.Rows[index].Cells[2].Controls[0])).Text.ToString().Trim();
  string liulan = ((TextBox)(GridView1.Rows[index].Cells[3].Controls[0])).Text.ToString().Trim();
  string sql = "update tg set title='" + title + "',zuozhe='" + zuozhe + "',liulan='"+liulan+"'where ID='" + ID + "'";
  HT web1 = new HT();
  web1.updata(sql);
  GridView1.EditIndex = -1;
  BindGrid();
  load();
  }

报错!!!
“/完整网站”应用程序中的服务器错误。

未将对象引用设置到对象的实例

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

------解决方案--------------------
未将对象引用设置到对象的实例。
应该是Web.Config出了问题。
你是不是用向导自动生成数据源的,如果是重新设置一次。
如果不是就检查Web.Config的连接字符串,看看里面的字符串名称和代码中用的名称是否一致。