Typically, I place the datapager control inside the layout template of the ListVIew control. This helps the format of the data pager to match the layout of the ListView.
Usually, I have a second control - a simple textbox called “txtPageSize”. I will initialize this with a value (like 10), and when it’s changed I update the pagesize parameter of the listview control.
Here’s an example of the text box
1 2 3 4 5 6 7
<asp:TextBox ID = "txtPageSize" runat = "server" Columns = "3" Text = "20" OnTextChanged="txtPageSize__TextChanged" AutoPostBack="True" />
When it is changed, it calls a routine ‘TxtPageSize__TextChanged”, here’s a sample of that routine.
PublicSub txtPageSize__TextChanged( _ ByVal sender AsObject, _ ByVal e As System.EventArgs) 'Handles txtPageSize.TextChanged
Dim txtPageSize As TextBox _ = lvAccounts.FindControl("txtPageSize")
Dim DataPager_VendorAccount As DataPager _ = lvAccounts.FindControl("DataPager_VendorAccount")
If IsNumeric(txtPageSize.Text) Then DataPager_VendorAccount.PageSize = txtPageSize.Text EndIf
If IsNumeric(txtPageSize.Text) Then DataPager_VendorAccount.PageSize = txtPageSize.Text SI.sys.ParmSetValue("VendorAccountList_Page_Size", txtPageSize.Text.ToString, BillPay.BO_Staff.Get_ID_byNtUserName(SI.sys.ntUserNameNoWG), 5) EndIf
EndSub
I adjust the control, but also I save this value into a systems parameter table, and reload it when the form is reconstructed. I do that with a few lines in the ListView PreRender event. Here’s a sample
1 2 3 4 5 6 7 8 9
ProtectedSub lvAccounts_PreRender(ByVal sender AsObject, ByVal e As System.EventArgs) Handles lvAccounts.PreRender ' ' page size logic Dim txtPageSize As TextBox _ = lvAccounts.FindControl("txtPageSize") Dim DataPager_VendorAccount As DataPager _ = lvAccounts.FindControl("DataPager_VendorAccount") txtPageSize.Text = SI.sys.ParmGetValue("VendorAccountList_Page_Size", "10", BillPay.BO_Staff.Get_ID_byNtUserName(SI.sys.ntUserNameNoWG), 5) DataPager_VendorAccount.PageSize = txtPageSize.Text
In theory when someone set’s the page size textbox, it is repopulated when they navigate back to the form.