【发布时间】:2012-01-19 15:38:51
【问题描述】:
我有一个看起来像这样的 GridView:
<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 会触发。
【问题讨论】:
-
何时将网格绑定到数据源,仅
if(!Postback)?! -
是的,问题是绑定没有包含在
if(!isPostBack)语句中。