Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing website in vb.net. I have used Listview to display products. There are couple of filters to refine search. I am showing 36 products in one page & have total 450 products in database. Problem is if I switched to page 1 to page 10 & then apply any filter from checkboxList & after applying filter it found 10 products then it shows blanks result but 10 product is there but it still on 10th page so not showing 10 products because it is on 1st page. Can any one help me how can I Rest pageIndex after applying filter? OnPagePropertiesChanged I tried to reset page Index after listview gets bind but it is not working.

What I have tried:

VB
Protected Sub OnPagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs)
        TryCast(products.FindControl("DataPager1"), DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
        Me.buildWhereClause()
        products.SelectedIndex = -1
    End Sub
Posted
Updated 28-Sep-16 3:48am

1 solution

You just need to re-populate your ListView with the updated datasource to reflect the changes after you paged and filter.

If you want to reset the page after filtering then you may need to write the logic at CheckBoxList changed event instead, and do something like this:

C#
DataPager pager = ListView1.FindControl("DataPagerId") as DataPager;
if (pager != null)
{
    pager.SetPageProperties(0, pager.PageSize, true);
}


VB.NET
VB
Dim pager As DataPager = TryCast(ListView1.FindControl("DataPagerId"), DataPager)
If pager IsNot Nothing Then
	pager.SetPageProperties(0, pager.PageSize, True)
End If

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================
 
Share this answer
 
v2
Comments
SuRaj Dedhia 28-Sep-16 11:05am    
It's not in c#. It is in VB. Any changes that I can make in my code which I posted?
Vincent Maverick Durano 28-Sep-16 11:45am    
Use an online converter tool to convert it to VB.NET. The change you need to is remove your code for setting the SelectedIndex and add the code I've provided at CheckBoxList event.
Vincent Maverick Durano 28-Sep-16 11:52am    
I've updated the code to include the VB.NET equivalent.
SuRaj Dedhia 28-Sep-16 23:45pm    
I have used your code in myCheckBoxListSelectedIndexChanged but it's not working. It stays on only page 1 if you click on 2,3,4 etc. Same Code I tried onPagePropertiesChanging but it's not going to other pages.
Vincent Maverick Durano 29-Sep-16 3:34am    
You don't need to apply the code in your onPagePropertiesChanging event so the paging will work normally.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900