Search code examples
c#asp.netlistviewupdatepanel

Asp.net Datapager Not refreshing while using updatepanel


I have used ListView topopulate products. My listview is inside update panel. Now when I go to second page with datapager then it goes to second page but datapager not refreshing. If I click on 2nd page then too firstpage button gets highlighted.

Aspx

<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <asp:ListView ID="products" runat="server" OnPagePropertiesChanging="OnPagePropertiesChanging">
        <ItemTemplate>
            Content Here
        </ItemTemplate>

        <LayoutTemplate>
            <div id="itemPlaceholderContainer" runat="server" style="">
                <div runat="server" id="itemPlaceholder" />
            </div>

            <div class="clearfix"></div>
            <div class="datapager">
                <asp:DataPager ID="DataPager1" ClientIDMode="Static" runat="server" PageSize="24" PagedControlID="products" ViewStateMode="Enabled">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="false" ShowPreviousPageButton="False" ShowNextPageButton="false" ButtonCssClass="nextPre" />
                        <asp:NumericPagerField ButtonType="Link" ButtonCount="10" />

                        <asp:NextPreviousPagerField ButtonType="Link" ShowNextPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="false" ButtonCssClass="nextPre" />
                    </Fields>
                </asp:DataPager>
                <div class="clear"></div>
            </div>
        </LayoutTemplate>
    </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>

Solution

  • You probably have a mistake inside OnPagePropertiesChanging. Difficult to tell since the code is missing, but it should look something like this.

    protected void OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        //get the correct page info from the datapager
        (products.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    
        //reload data and rebind the listview
        products.DataSource = mySource;
        products.DataBind();
    }