У меня возникли проблемы с методом RowUpdating
. Мой GridView
подключен к нашему локальному SQL Server, и я пытаюсь обновить данные. Вот код для метода RowUpdating
из MSDN.ASP.NET RowUpdating GridView Troubles
protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["TaskTable"];
//Update the values.
GridViewRow row = GridView1.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["Id"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Description"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["IsComplete"] = ((CheckBox)(row.Cells[3].Controls[0])).Checked;
//Reset the edit index.
GridView1.EditIndex = -1;
//Bind data to the GridView control.
BindData();
}
Я получаю эту ошибку:
System.NullReferenceException: Object reference not set to an instance of an object.
Вы получаете доступ так много элементов без нулевых проверок, что это может быть любое количество вещей. Какая строка бросает исключение? Вы уверены, что все элементы управления существуют в ячейках, которые вы указываете? Вы уверены, что сами клетки существуют? –