Data Pager in user controls does not work

Topics: Troubleshooting
Jun 7, 2011 at 4:13 AM

Hi when I add a usercontrol that has a datapager control on it to control a listview in the user control, the datapager does a postback, but returns the same page.

Developer
Jun 7, 2011 at 10:33 AM

I try make datapager + listview and everything works ok.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListView.ascx.cs" Inherits="Controls_ListView" %>
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
	<Fields>
		<asp:NumericPagerField ButtonType="Link" />
		<asp:NextPreviousPagerField ButtonType="Button" ShowPreviousPageButton="true" ShowNextPageButton="true"
			ShowFirstPageButton="false" ShowLastPageButton="false" />
	</Fields>
</asp:DataPager>
<hr />
<asp:ListView ID="ListView1" runat="server" OnPagePropertiesChanged="ListView1_PagePropertiesChanged">
	<ItemTemplate>
		<%# Eval("Title") %>
		<br />
	</ItemTemplate>
</asp:ListView>
<hr />
<asp:DataPager ID="DataPager2" runat="server" PagedControlID="ListView1">
	<Fields>
		<asp:NextPreviousPagerField ButtonType="Button" ShowPreviousPageButton="true" ShowNextPageButton="true"
			ShowFirstPageButton="false" ShowLastPageButton="false" />
	</Fields>
</asp:DataPager>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Composite.Data;
using Composite.Data.Types;

public partial class Controls_ListView : System.Web.UI.UserControl
{
	protected void Page_Load(object sender, EventArgs e)
	{

		if (!IsPostBack)
		{
			BindListView();
		}
	}

	protected void ListView1_PagePropertiesChanged(object sender, EventArgs e)
	{
		BindListView();
	}

	private void BindListView()
	{
		using (var connection = new DataConnection(PublicationScope.Published))
		{
			ListView1.DataSource = connection.Get<IPage>().ToList();
			ListView1.DataBind();
		}
	}
}

Jun 8, 2011 at 10:44 PM

Thanks for your reply, I had just changed from running off a datasource server control and I had implemented the page change event but had not rebinded, thanks for the heads up.