[英]The GridView ' ' fired event RowUpdating which wasn't handled. C# code behind asp.net
There are similar questions on Stackoverflow and other websites, but I seem to miss something. 在Stackoverflow和其他网站上也有类似的问题,但我似乎错过了一些东西。
I have a GridView bound to a DataTable which comes from a database. 我有一个GridView绑定到来自数据库的DataTable。 My goal is to update the one row at the time with a button which is in the same row which calls the following Method.
我的目标是同时使用同一行中的按钮来更新一行,该按钮将调用以下方法。
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);
}
It is being called from here: 从这里被调用:
<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>
At my first try I had a OnRowCommand with the GridViewCommandEventArgs at the code behind. 第一次尝试时,在后面的代码中有一个带有GridViewCommandEventArgs的OnRowCommand。
But it still throws the same exception, although I've read on a couple of sites that changing it to OnRowEditing and GridViewEditEventArgs would solve the problem. 但这仍然引发相同的异常,尽管我在几个站点上都读过过,将其更改为OnRowEditing和GridViewEditEventArgs可以解决问题。
Thanks in advance, 提前致谢,
Tim A 蒂姆·A
GridView's in ASP.NET have some built in commands - Deleted
, Update
, etc. What's happening is that your button has a command name of Update
, and the Gridview is hijacking that from you and firing a RowUpdating
event instead of your RowEditing
event. ASP.NET中的GridView具有一些内置命令
Deleted
, Update
等。发生的是您的按钮的命令名称为Update
,而Gridview劫持了您的该命令并触发了RowUpdating
事件而不是RowEditing
事件。 Change your button command name to be Edit
, and use a RowEditing
event. 将按钮命令名称更改为
Edit
,并使用RowEditing
事件。
If you are using the Row_Command
event to edit, then don't use the button command name "Update" for Update and "Delete" for Delete. 如果要使用
Row_Command
事件进行编辑, Row_Command
按钮命令名“ Update”用于更新,而将“ Delete”用于删除。 Instead, use Edit or UP and Del respectively. 而是分别使用Edit或UP和Del。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.