有#2和其他网站类似的问题,但我似乎错过的东西。GridView'触发事件RowUpdating未处理。 C#代码背后asp.net
我有一个绑定到来自数据库的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会解决这个问题的网站阅读。
由于提前,
添
我已经试过了。但是现在更新方法不再被按钮调用。但它也没有抛出异常。 –
啊,明白了。你是对的地方,但我改变了'编辑',现在它的工作:)谢谢指出我在正确的方向!如果你改变你的答案,我将设置就是答案:) –
很抱歉的响应晚了,但我的意思的CommandName =“编辑” :) –