Stackoverflowや他のウェブサイトにも同様の質問がありますが、私は何かを見逃しているようです。
データベースから取得したDataTableにGridViewをバインドしています。私の目標は、次のメソッドを呼び出す同じ行にあるボタンを使用して、一度に1行ずつ更新することです。
protected void TestsToBeDone_RowUpdating(object sender, GridViewEditEventArgs e)
{
SqlConnection myConnection = getConnection();
myConnection.Open();
int index = Convert.ToInt32(e.NewEditIndex);
GridViewRow selectedRow = TestsToBeDone.Rows[index];
TableCell LABAVIDc = selectedRow.Cells[1];
int LABAVID = Convert.ToInt32(LABAVIDc.Text);
TableCell assistentc = selectedRow.Cells[5];
string query = "UPDATE Labaanvraag " +
"SET Status='4' "+
"WHERE LABAVID ='"+LABAVID+"'";
}
SqlCommand commandZ = new SqlCommand(query, myConnection);
commandZ.ExecuteNonQuery();
myConnection.Close();
SetPatientTestGrid(Session["PATID"], e);
}
ここから呼び出されています:
<asp:GridView ID="TestsToBeDone" runat="server" EnableModelValidation="True" OnRowEditing="TestsToBeDone_RowUpdating">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="Update"
HeaderText="Afgenomen" ShowHeader="True" Text="Afgenomen" />
</Columns>
</asp:GridView>
私の最初の試みでは、コードビハインドにGridViewCommandEventArgsを含むOnRowCommandがありました。
ただし、OnRowEditingとGridViewEditEventArgsに変更すると問題が解決することをいくつかのサイトで読んだことがありますが、それでも同じ例外がスローされます。
前もって感謝します、
ティムA