On a project I’m working on, I have many <asp:ListView> controls, which are paginated using <asp:DataPager> controls. Instead of copying and pasting the controls to each .aspx page where I have a paginated list, would it be possible to break out the <asp:DataPager> controls into a reusable/modular .ascx control and create a field on it to pass in the PagedControlID?
I’ve tried this in the past but couldn’t not seem to target the PagedControlID in the Parent page.
Here’s what I’ve got so far. Any help would be much appreciated.
.aspx Page
<abc:Pagination ID="uxPagination" ListControlID="uxEventListView" runat="server" />
.ascx Pagination Control
<asp:DataPager ID="uxDataPager" PageSize="1" runat="server" />
.ascx.cs Pagination Control
public partial class ABC_UserControls_Pagination : System.Web.UI.UserControl
{
private string listControlID;
public string ListControlID
{
get { return listControlID; }
set { listControlID = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(ListControlID))
{
uxDataPager.PagedControlID = ListControlID;
}
}
}
Apologies about the delay. This seemed to do the trick. Now with your UserControl you will be able to pass through a control ID (in my case a ListView) and your preferred item count per page.