DataGrid中按钮列的事件
private void borrow(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataRow dr=dataSet11.Tables["Document"].Rows.Find(e.Item.Cells[0].Text);
dr["borrow"]="1";
dr["borrower"]=Session["username"];
sqlDA1.Update(dataSet11,"Document");
DataGrid1.DataSource=dataSet11.Tables["Document"];
DataGrid1.DataBind();
}未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误: 
行 235: dr["borrow"]="1";不明白是为什么?

解决方案 »

  1.   

    dr["borrow"]
    -->
    dr["Document"]
      

  2.   

    不好意思,看错了,你跟踪看看dataSet11.Tables["Document"]有没包含"borrow"列
      

  3.   

    DataRow dr=dataSet11.Tables["Document"].Rows.Find(e.Item.Cells[0].Text);Rows.Find(e.Item.Cells[0].Text);后dr可能为空了
      

  4.   

    dataSet11.Tables["Document"].Rows.Find(e.Item.Cells[0].Text);
    返回null值,没有符合的相关记录
      

  5.   

    不应该没有记录啊,我是用DataGrid的添加按钮列做的,就是一个记录后面多了一个按钮,点击按钮来对点击的该行记录进行操作,记录是有的。另外这个表中“borrow”和“borrower”两个字段也是有的,数据预览时也能看到,没问题的。
    不知道是哪出错,我觉得可能的地方都看了一遍。