我想从 gridview 中删除一行。这是我的代码
//page load event
if(page.isPostback==false)
{
dataset ds=null;
ds=(dataset)Session["ds1"];
//session will contain dataset ds1 with data selected by user
if(ds!=null)
{
gvdetails.datasource=ds.Tables["Bus_Table"];
gvdetails.DataBind();
}
}
protected void gvdetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataSet ds = (DataSet)Session["ds1"];
ds.Tables["Bus_Table"].Rows[e.RowIndex].Delete();
ds.Tables["Bus_Table"].AcceptChanges();
Session["ds1"] = ds;
gvDetails.DataSource = ds.Tables["Bus_Table"];
gvDetails.DataBind();
}
代码工作正常,但是当我尝试单击删除链接时。我在这一行“ds.Tables["Bus_Table"].Rows[e.RowIndex].Delete();”中收到运行时错误
error :Object reference not set to an instance of an object.NULLREFERENCEEXCEPTION was unhandled by the usercode.Use the "new " keyword to create an object instance
我无法弄清楚问题所在。请帮忙