Home > DeveloperSection > Forums > ListView and DataPager not working
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    August-25-2014 1:18 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 788  View(s)
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!



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-25-2014 2:19 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick