Stackoverflow 和其他网站上有类似的问题,但我似乎错过了一些东西。
我有一个绑定到来自数据库的 DataTable 的 GridView。我的目标是使用同一行中调用以下方法的按钮一次更新一行。
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 可以解决问题。
提前致谢,
蒂姆一个