问题描述
我有一个GridView。标记是这样的...
I have a gridview. Markup is like this...
<asp:GridView ID="gvwServers" runat="server" class="gvwServers"
AutoGenerateColumns="false" OnRowEditing="gvwServers_Edit"
onrowcancelingedit="gvwServers_Cancelling" onrowdeleting="gvwServers_Deleting"
onrowupdated="gvwServers_Updated" onrowupdating="gvwServers_Updating"
AutoGenerateEditButton=true AutoGenerateDeleteButton=true>
<columns>
<asp:CommandField ButtonType="Button" EditText="Edit" ShowEditButton="true" />
<asp:CommandField ButtonType="Button" EditText="Delete" ShowDeleteButton="true" />
...Bound fields and template fields etc...
我的code-背后都有这...
My Code-behind has this...
protected void gvwServers_Edit(object sender, GridViewEditEventArgs e)
{
gvwServers.EditIndex = e.NewEditIndex;
gvwServers.DataBind();
}
protected void gvwServers_Updated(object sender, GridViewUpdatedEventArgs e)
{
gvwServers.DataBind();
}
protected void gvwServers_Updating(object sender, GridViewUpdateEventArgs e)
{
gvwServers.DataBind();
}
protected void gvwServers_Deleting(object sender, GridViewDeleteEventArgs e)
{
gvwServers.DataBind();
}
protected void gvwServers_Cancelling(object sender, GridViewCancelEditEventArgs e)
{
e.Cancel = true;
gvwServers.EditIndex = -1;
gvwServers.DataBind();
}
问题是,大多数这些例程火正确,即编辑,删除,取消。的除了的,当我点击更新按钮, gvwServers_Edit()
火灾。这究竟是为什么?如何让我的更新按钮点击火 gvwServers_Updating()
?
The thing is that most of these routines fire correctly ie Edit, Delete, Cancel. Except when I click the Update button, gvwServers_Edit()
fires. Why is this happening? How do I make the Update button click fire gvwServers_Updating()
?
更新:我的问题解决了here.
推荐答案
您可以在活动的功能重新映射。
You can always re-map the event to the function..
嘛......几乎编辑事件只能映射到具有函数(对象发件人,GridViewCancelEditEventArgs E)
作为参数,可以同样更新的功能必须有(对象发件人,GridViewUpdatedEventArgs E)
参数...
Well almost...the "Edit" events can only map to a function that has (object sender, GridViewCancelEditEventArgs e)
as params, likewise update functions must have (object sender, GridViewUpdatedEventArgs e)
params...
您可以使用pre-作出事件处理函数或使自己的,再次关键是在'E'参数类型。
You can use the pre-made event handling function or make your own, again the key being the 'e' param type.
如果你想有两个编辑()和更新()事件的常用功能,把那个code到一个单独的函数被称为处理这些事件时,火。
If you want to have common functionality for both the Edit() and Updating() event, put that code into a separate function that is called by the handlers when those events fire.
这篇关于Update按钮触发编辑事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!