How to reference ListView DataPager from code-behind

2.6k Views Asked by At

For a ListView control DataPager, I'm trying to programmatically set the PageSize, but from the code-behind, I'm not able to see the datapager.

Trying to do this:

DataPager1.PageSize = 10

But "DataPager1" isn't accessible from the code behind page.

Thanks, Adam

1

There are 1 best solutions below

0
aanund On

If your DataPager is inside the ListViews LayoutTemplate it is not directly accessible from codebehind.

To get access to the DataPager, you must use the ListViews FindControl method.

DataPager pager = YourListViewID.FindControl("DataPager1") as DataPager;

Remember to check if the pager object is found (different from null) before using it.