GridView RowCommand 事件未触发 [英] GridView RowCommand event not firing

查看:34
本文介绍了GridView RowCommand 事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的 GridView:

I have a GridView that looks something like this:

<asp:GridView 
    ID="GridView1"
    AllowPaging="true"
    OnRowCommand="RowCommand"
    OnPageIndexChanging="gridView_PageIndexChanging"
    Runat="server">
    <Columns>
        ...
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="Button1" ButtonType="Button" CommandName="ItemExport" CommandArgument='<%# Eval("EXPORT") %>'
                    Text="Export" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        ...
    </Columns>
 </asp:GridView>

这是RowCommand:

protected void RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "ItemExport")
    {
        // etc.
    }
}

单击按钮根本不会触发 RowCommand 事件.但是,当我单击 GridView 的寻呼机中的页面索引时,会触发 RowCommand.

Clicking the button is not firing the RowCommand event at all. However, RowCommand fires when I click a page index in the GridView's pager.

推荐答案

您必须在 Page_Load 中的回发时绑定您的网格,只有当某些更改导致网格重新加载数据时(fe Sorting,分页)并且仅在适当的事件处理程序中.

You must not bind your grid on postbacks in Page_Load, only when something changed that causes the Grid to reload data(f.e. Sorting,Paging) and only in the appropriate event-handlers.

另一个可能的原因:您是否在某处禁用了 ViewState?

Another possible reason: Have you disabled ViewState somewhere?

这篇关于GridView RowCommand 事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆