GridviewPager not route onpaging event

139 views Asked by At

I have a problem with asp.net gridviewpager. When i click pager any page it routes to OnRowCommand event. I am waiting to route OnPageIndexChanging I have define my gridview like this.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
        GridLines="None" PageSize="4" AllowPaging="True" EmptyDataText="No record found"
        OnPageIndexChanging="OnPaging" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="RowCommand"
        CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="Id" />
            <asp:BoundField DataField="Baslik" HeaderText="Baslik" />
            <asp:BoundField DataField="KisaAciklama" HeaderText="Kısa Acıklama" />
            <asp:TemplateField HeaderText="Güncelle">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lnkView" CommandArgument='<%#Eval("Id") %>' CommandName="VIEW">Güncelle</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Sil">
                <ItemTemplate>
                    <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%#Eval("Id") %>'
                        CommandName="DELETE">Sil</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <%----%>
        </Columns>
    </asp:GridView>

Also my back-end code is

  protected void RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LinkButton lnkView = (LinkButton)e.CommandSource;
        string Id = lnkView.CommandArgument;
        if (e.CommandName == "VIEW")
        {
            Response.Redirect("/Views/AdminPages/Kayit.aspx?cmd=Update&id="+Id);

        }
        else if (e.CommandName == "DELETE")
        {

            kayitService.DeleteKayit(Convert.ToInt32(Id));
        }
    }


    protected void OnPaging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
1

There are 1 answers

0
AudioBubble On

Please try this

<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" BackColor="White"  

BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
onpageindexchanging="gvPerson_PageIndexChanging"
onrowcancelingedit="gvPerson_RowCancelingEdit"
onrowdatabound="gvPerson_RowDataBound" onrowdeleting="gvPerson_RowDeleting"
onrowediting="gvPerson_RowEditing" onrowupdating="gvPerson_RowUpdating"
onsorting="gvPerson_Sorting">

    <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:BoundField DataField="Baslik" HeaderText="Baslik" />
        <asp:BoundField DataField="KisaAciklama" HeaderText="Kısa Acıklama" />
        <asp:TemplateField HeaderText="Güncelle">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkView" CommandArgument='<%#Eval("Id") %>' CommandName="VIEW">Güncelle</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Sil">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkDelete" CommandArgument='<%#Eval("Id") %>'
                    CommandName="DELETE">Sil</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <%----%>

</Columns> 

Back-end code may be :

protected void gvPerson_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // Set the index of the new display page.  
        Gridview1.PageIndex = e.NewPageIndex;
        // Rebind the GridView control to  
        // show data in the new page. 
        BindGridView();
    }

According to my opinion the code which I mentioned above is the most appropriate code for Paging.