LISTVIEW AND DATAPAGER NOT WORKING

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
 1048  View(s)
Ratings:
Rate this:

I used a DataPager to page through ListView data. When ListView bound, DataPager show many pages below, everything seems to be ok but when i click to another page, After a postback, ListView is empty with EmptyDataTemplate and of course without pages.

    protected void DatapPager_OnPreRender(object sender, EventArgs e)

    {

        try

        {

            listView.DataSource = ((DataSet)ViewState[VIEWSTATE_DATASET]).Tables[0];

            listView.DataBind();

        }

        catch (System.Exception ex)

        {              

        }           

        base.OnPreRender(e);

    }

 

    protected void listView_OnPagePropertiesChanged(object sender, EventArgs e)

    {

        try

        {

            listView.DataSource = ((DataSet)ViewState[VIEWSTATE_DATASET]).Tables[0];

            listView.DataBind();

        }

        catch (System.Exception ex)

        {              

        }           

    }

In my case, ListView's data bound in a click event, not on PageLoad.

Anyone can helps me? Thank you so much!

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: ListView and DataPager not working

    Hi jay, 

    Its Simple, Just Get "ID" in "QUERY-STRING" from the Database, Now Set it to the Pager Control Property as [QueryStringField="ID"] like:

    <asp:DataPager ID="DataPagerProducts" runat="server" QueryStringField="ID" PageSize="3">

                                <Fields>

                                    <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" />

                                    <asp:NumericPagerField />

                                    <asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" />

                                </Fields>

                            </asp:DataPager>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!