如何忽略gridview的RowCommand事件 [英] how to neglect RowCommand event of gridview
问题描述
即使我没有在gridview上按下链接按钮,如何忽略gridview的RowCommand事件?当我单击Gridview上的链接"按钮时,RowCommand事件被触发.
how to neglect RowCommand event of gridview even i didn''t press link button on gridview? when i clicked on Link Button on Gridview ,RowCommand event fired. it''s OK
推荐答案
在您的事件处理程序中,请执行以下操作:
In your event handler, do this:
if (sender is LinkButton)
{
return;
}
在您的RowCommand函数声明后面的代码中,仅使用您命名的名称,它的外观将类似于此.
受保护的void GridView1_RowCommand(对象发送者,GridViewCommandEventArgs e)
然后,您可以在函数内部确定使用GridViewCommandEventArgs e触发了哪个事件并执行适当的操作.
例如,您可以编写以下
In your code behind your RowCommand function declartion will look something like this, only with whatever you named it.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
Inside of the function you can then determine which event was fired with the GridViewCommandEventArgs e and perform the appropriate action.
For example you could code the following
if (e.CommandName == "Activation")
{
//call function to Activate a user
}
您可以在aspx页面上的各种按钮上指定这些命令,例如,
These commands can be specified by you in your aspx page on your various buttons like so,
<asp:buttonfield headertext="Activate User" text="Activate" commandname="Activation" />
最后,要使所有这些都能在aspx页面上的Gridview声明中起作用,您需要设置OnRowCommand ="GridView1_RowCommand"或您决定命名函数的任何名称.
很抱歉,我没有时间进一步详细说明,但是,如果这不能解决您的问题,请告诉我,我将尝试更加具体.
Finally for all of this to work in your Gridview declaration on your aspx page you need to have set OnRowCommand="GridView1_RowCommand" or whatever you decide to name your function.
I''m sorry I don''t have time to be more detailed, but if this doesn''t fix your problem, please let me know and I will try to be more specific.
这篇关于如何忽略gridview的RowCommand事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!