omnia Mm
omnia Mm

Reputation: 157

Datagridview paging does not ever fire

i know the question may be silly , but i have been searching for 2 hours but with no result i have a data grid view with paging and when i select page 2 or any thing it never works and come back with page 1 here is the code

<asp:DataGrid ID="gvRatings" runat="server" AllowPaging="true" PageSize="20"
PagerStyle-Mode="NumericPages" OnPageIndexChanged="gvRatings_PageIndexChanged" >
<PagerStyle HorizontalAlign="right" CssClass="Normal"/>
<Columns>
    <asp:TemplateColumn >
        <ItemTemplate>
            <asp:HyperLink ID="lnkListingName" runat="server"></asp:HyperLink>
        </ItemTemplate>
    </asp:TemplateColumn>
</Columns>

and this is the page load

 protected void Page_Load(object sender, EventArgs e)
    {
            BindRatingsDG();
            BindRatingsStatsDG();
    }

and this is the paging event ,,

protected void gvRatings_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
    {
        //Set grid view page index with the new page index selected
        gvRatings.CurrentPageIndex = e.NewPageIndex;
        gvRatings.DataBind();
        BindRatingsDG();
    }

at the debug the arrow hit the load and the bind function but never hit the paging function ?? what am i doing wrong ? thnx in advance for your help

Upvotes: 0

Views: 521

Answers (2)

Anders Wendt
Anders Wendt

Reputation: 369

You should check the Page.IsPostBack flag in the PageLoad.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        BindRatingsDG();
        BindRatingsStatsDG();
    }
}

Upvotes: 1

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

Your GridView is getting binded on every postback of the pager link you click.

You should modify your Page load function as below

protected void Page_Load(object sender, EventArgs e)

{
     if(!Page.IsPostBack)
      {
        BindRatingsDG();
        BindRatingsStatsDG();
      }
}

Upvotes: 0

Related Questions