如何更新gridview行事件args

时间:2013-02-18 06:50:39

标签: asp.net sql gridview databound

         Design.apsx[1]

GridView.aspx.cs

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

    //Retrieve the table from the session object.
    DataTable dt = (DataTable)Session["Sql2008.Services"];

    //Update the values.
    GridViewRow row = GridView1.Rows[e.RowIndex];
    dt.Rows[row.DataItemIndex]["FirstName"] = ((TextBox)(row.Cells[1].Controls[0])).Text;//null reference thrown
    dt.Rows[row.DataItemIndex]["LastName"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
    dt.Rows[row.DataItemIndex]["Product"] = ((TextBox)(row.Cells[3].Controls[0])).Text;
    dt.Rows[row.DataItemIndex]["Mobile"] = ((TextBox)(row.Cells[4].Controls[0])).Text;
    dt.Rows[row.DataItemIndex]["City"] = ((TextBox)(row.Cells[5].Controls[0])).Text;
    dt.Rows[row.DataItemIndex]["Store"] = ((TextBox)(row.Cells[6].Controls[0])).Text;
    dt.Rows[row.DataItemIndex]["Details"] = ((TextBox)(row.Cells[7].Controls[0])).Text;
    //Reset the edit index.
    GridView1.EditIndex = -1;

    //Bind data to the GridView control.
    bind();

}
public void bind()
{

    GridView1.DataSource = Session["Sql2008.Services"];
    GridView1.DataBind();

}

当我更新网格视图时,它会抛出对象引用未设置为对象的实例,它表示在Gridview.aspx.cs中我得到了提到的错误

0 个答案:

没有答案