I am using a DataPager to control how much data from my DB is show on the page at one time. The pager displays fine and even the amount of pages increases as I add more data. The problem is that if I click any of the buttons or page numbers to change the
data displayed nothing happens, and no errors are logged by Elmah. Can anyone help me get the DataPager working correctly? This is the code I use for the DataPager.
So now I placed it in the LayoutType and I get an the error
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added
during a post-back must match the type and position of the controls added during the initial request.
I see you are using an UpdatePanel. The DataPager will have to be outside the ListView, but inside the UpdatePanel for it to work.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
That's odd. You have the DataPager inside the UpdatePanel, and when you click a button on it you get an error page? Or is the Exception only in the debugger?
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
How are you binding the ListView? It doesn't look like you're using one of the data source controls, so you'll need to handle the PagePropertiesChanged event and bind your list to the new page of data.
How are you binding the ListView? It doesn't look like you're using one of the data source controls, so you'll need to handle the PagePropertiesChanged event and bind your list to the new page of data.
lvSearchResults.DataSource = SQLHelper.GetDataByQuery("SELECT FROM TABLE);
lvSearchResults.DataBind();
This is all done in the Page_Load method. That is not my real select statment though
Eagle_f90
Member
467 Points
545 Posts
DataPager control not working on ListView
Sep 08, 2012 10:20 PM|LINK
I am using a DataPager to control how much data from my DB is show on the page at one time. The pager displays fine and even the amount of pages increases as I add more data. The problem is that if I click any of the buttons or page numbers to change the data displayed nothing happens, and no errors are logged by Elmah. Can anyone help me get the DataPager working correctly? This is the code I use for the DataPager.
<asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" /> <asp:NumericPagerField ButtonCount="10" /> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" /> </Fields> </asp:DataPager>emonti
Participant
1406 Points
291 Posts
Re: DataPager control not working on ListView
Sep 08, 2012 11:05 PM|LINK
put in into the layout template
Eagle_f90
Member
467 Points
545 Posts
Re: DataPager control not working on ListView
Sep 09, 2012 01:45 AM|LINK
So now I placed it in the LayoutType and I get an the error
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
<asp:UpdatePanel ID="upSearchResults" runat="server"> <ContentTemplate> <asp:Label ID="lblErrorMSG" CssClass="ErrorText" runat="server" /> <asp:Panel ID="plSearchResults" runat="server"> <table style="width: 100%" border="1"> <tr> <td> <asp:Literal ID="lblTitleRow" runat="server" /> </td> <td> <asp:Literal ID="lblDescriptionRow" runat="server" /> </td> <td class="TableSelectButton"> <asp:Button ID="btnAddNewItem" Text="Select" runat="server" /> </td> </tr> <asp:ListView ID="lvSearchResults" runat="server"> <LayoutTemplate> <tr id="itemPlaceHolder" runat="server" /> <tr class="Center"> <td colspan="3"> <asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" /> <asp:NumericPagerField ButtonCount="10" /> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" /> </Fields> </asp:DataPager> </td> </tr> </LayoutTemplate> <ItemTemplate> <tr> <td> <%#Eval("Title")%> </td> <td> <%#Eval("Descript")%> </td> <td class="TableSelectButton"> <asp:Button ID="btnEditItem" Text="Select" PostBackUrl='<%#String.Format("{0}.aspx?ID={1}&SectionID={2}", Eval("PageName"), Eval("ID"), ddlMediaTitle.SelectedValue.ToString())%>' runat="server" /> </td> </tr> </ItemTemplate> </asp:ListView> </table> </asp:Panel> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" /> </Triggers> </asp:UpdatePanel>superguppie
All-Star
48225 Points
8679 Posts
Re: DataPager control not working on ListView
Sep 10, 2012 09:57 AM|LINK
I see you are using an UpdatePanel. The DataPager will have to be outside the ListView, but inside the UpdatePanel for it to work.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
emonti
Participant
1406 Points
291 Posts
Re: DataPager control not working on ListView
Sep 10, 2012 02:58 PM|LINK
Also: from http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datapager.aspx
You can associate the DataPager control with the data-bound control by using the PagedControlID property.
Eagle_f90
Member
467 Points
545 Posts
Re: DataPager control not working on ListView
Sep 11, 2012 01:23 AM|LINK
If you look at my code you will notice I have already added the PagedControlID
I just tryed moving it out of the ListView but keeping it in the pannel and get the same error:
<asp:UpdatePanel ID="upSearchResults" runat="server"> <ContentTemplate> <asp:Label ID="lblErrorMSG" CssClass="ErrorText" runat="server" /> <asp:Panel ID="plSearchResults" runat="server"> <table style="width: 100%" border="1"> <tr> <td> <asp:Literal ID="lblTitleRow" runat="server" /> </td> <td> <asp:Literal ID="lblDescriptionRow" runat="server" /> </td> <td class="TableSelectButton"> <asp:Button ID="btnAddNewItem" Text="Select" runat="server" /> </td> </tr> <asp:ListView ID="lvSearchResults" runat="server"> <LayoutTemplate> <tr id="itemPlaceHolder" runat="server" /> </LayoutTemplate> <ItemTemplate> <tr> <td> <%#Eval("Title")%> </td> <td> <%#Eval("Descript")%> </td> <td class="TableSelectButton"> <asp:Button ID="btnEditItem" Text="Select" PostBackUrl='<%#String.Format("{0}.aspx?ID={1}&SectionID={2}", Eval("PageName"), Eval("ID"), ddlMediaTitle.SelectedValue.ToString())%>' runat="server" /> </td> </tr> </ItemTemplate> </asp:ListView> </table> </asp:Panel> <div class="Center"> <asp:DataPager ID="dpSearchResults" PagedControlID="lvSearchResults" PageSize="10" runat="server"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="false" ShowFirstPageButton="true" ShowLastPageButton="false" ShowPreviousPageButton="true" /> <asp:NumericPagerField ButtonCount="10" /> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowFirstPageButton="false" ShowLastPageButton="true" ShowPreviousPageButton="false" /> </Fields> </asp:DataPager> </div> </ContentTemplate>superguppie
All-Star
48225 Points
8679 Posts
Re: DataPager control not working on ListView
Sep 11, 2012 11:05 AM|LINK
That's odd. You have the DataPager inside the UpdatePanel, and when you click a button on it you get an error page? Or is the Exception only in the debugger?
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
Eagle_f90
Member
467 Points
545 Posts
Re: DataPager control not working on ListView
Sep 11, 2012 03:28 PM|LINK
No error is generated at all, I click and nothing happens.
RichardD
Contributor
3950 Points
549 Posts
Re: DataPager control not working on ListView
Sep 11, 2012 04:34 PM|LINK
How are you binding the ListView? It doesn't look like you're using one of the data source controls, so you'll need to handle the PagePropertiesChanged event and bind your list to the new page of data.
Eagle_f90
Member
467 Points
545 Posts
Re: DataPager control not working on ListView
Sep 11, 2012 04:40 PM|LINK
lvSearchResults.DataSource = SQLHelper.GetDataByQuery("SELECT FROM TABLE); lvSearchResults.DataBind();This is all done in the Page_Load method. That is not my real select statment though