Tôi có một GridView mà trông giống như sau:GridView RowCommand sự kiện không bắn
<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>
Đây là RowCommand
:
protected void RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ItemExport")
{
// etc.
}
}
Nhấp vào nút không được bắn sự kiện RowCommand
ở tất cả. Tuy nhiên, RowCommand
sẽ kích hoạt khi tôi nhấp vào một chỉ mục trang trong máy nhắn tin của GridView.
Khi nào bạn ràng buộc lưới của mình với Nguồn dữ liệu, chỉ 'if (! Postback)' ?! –
Đúng, vấn đề là ràng buộc không được bao bọc trong câu lệnh 'if (! IsPostBack)'. –