简体   繁体   中英

GridView Events are not Firing in asp.net?

I am using a Gridview but the events are not firing?

 <asp:GridView ID="GridView3" runat="server" ShowHeaderWhenEmpty="true" DataKeyNames="Ac_Code" AutoGenerateColumns="False"
              AllowPaging="true" PageSize="10" Width="100%" BorderStyle="Solid" style="overflow:auto" OnSelectedIndexChanged="GridView3_SelectedIndexChanged"  OnRowDataBound="GridView3_RowDataBound" AllowSorting="true" OnSorting="GridView3_Sorting" OnRowCreated="GridView3_RowCreated">
                    <AlternatingRowStyle BackColor="#CCCCFF" />
                    <Columns>                      
                        <asp:BoundField DataField="Ac_Code" HeaderText="A/c Code" SortExpression="Ac_Code" ItemStyle-Width="12%" ItemStyle-HorizontalAlign="Left" HeaderStyle-CssClass="Dth" />
                        <asp:BoundField DataField="Ac_Name" HeaderText="Account" SortExpression="Ac_Name" ItemStyle-Width="12%" ItemStyle-HorizontalAlign="Left" HeaderStyle-CssClass="Dth"/>
                        <asp:BoundField DataField="Ac_Sub_Group_Name" HeaderText="A/c Sub Group" SortExpression="Ac_Sub_Group_Name" ItemStyle-Width="12%" ItemStyle-HorizontalAlign="Left" HeaderStyle-CssClass="Dth" />
                        <asp:CommandField SelectText="Select" ShowSelectButton="true" Visible="false" />
                    </Columns>

                </asp:GridView>

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

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        grid.DataBind();
    }
}

Another possible reasons: a. Have you disabled ViewState somewhere? b. onrowcommand= attribute not being set in the asp:GridView element. This should be set to the name of the handler which will be handling the event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM