Last post Mar 10, 2014 05:42 PM by crouchie2004
Mar 06, 2014 05:55 PM|crouchie2004|LINK
Before I get links to code pages on using the repeater control with paging I must stress that what I am trying to achieve doesn't seem to be on the Internet, hence my question here.
I am using a SQL query to return all the resuls from a database table and displaying on a page. Of form load I wish for these results to be paged (10 or 20 per page) but this is where things change. I wish for the user to be able to filter the results and
I already have that working (code below) but I need all the results paged.
I have a function that returns the dataset which I bind the repeater to on form load which is just normal code.
Protected Function MyFunctionNameHere() As DataSet
Dim strConnectionString As String = ConfigurationManager.ConnectionStrings("MyConnectionStringName").ConnectionString
Dim con As SqlConnection = New SqlConnection(strConnectionString)
Dim strSQL As String = "SELECT * FROM MyDatabaseTable"
Dim ds As DataSet
Dim da As New SqlDataAdapter(strSQL, con)
ds = New DataSet
The filtering is just this:
Dim dv As DataView = New DataView(MyDataset.Tables("MyDatasetTableNameHere"))
dv.RowFilter = "Like '%" & MySearchBoxNameHere.Text.Trim & "%'"
MyRepeaterControl.DataSource = dv
I read that I need to use a PagedDataSource then bind that to the repeater control
I can take the DataSet then pass to the PagedDataSource like so:
Dim pds As PagedDataSource = New PagedDataSource
pds.AllowPaging = True
pds.PageSize = 10
pds.DataSource = MyDataset.Tables("MyDatasetTableNameHere").DefaultView
MyRepeaterControl.DataSource = pds
But unfortunately the fliter is calling the function to return the results on every filter (Search Button Event). Need to stop that as I don't wish to be contacting the database with every search plus I need the filter results to be paged. How can I achieve
what I wish to do plus show the page numbers (if results are greater than the page size) and handle the page changing?
Mar 06, 2014 11:48 PM|anuj_koundal|LINK
Hi Crouchie I advise you to use Listview instead of Repeater as Listview has inbuilt paging functionality and It has same features like repeater control.
Mar 07, 2014 07:51 AM|crouchie2004|LINK
Thanks for your reply
The reason I wish to use a Repeater rather than the ListView is because I like to have a break from the norm. I know it can be done in the repeater but no-one I have found can do it.
In an article on Code Project it shows how to use a link label for the pages but these don't show in Firefox apparently although uses a QueryString for paging. which would be SEO friendly. In an article from 4 Guys From Rolla it shows the Previous/Next buttons
and they work in my code. However, no-one has an example that contains both. Add a filter on top... I have a couple of support requests left with my MSDN subscription so may pose this question to Microsoft and let them write the code.
The problem I am having is that when I use the DataView it uses the database for each query not the already returned dataset rather than just filtering the results of the original one but then I cannot page it. That means it's using two datasources. Preventing
SQL Injection attacks is why I wish to filter. All the code will eventually be put into a DLL
Usually what happens is I spend hours searching then net and as a last resort post a question on ASP.NET, no-one ever seems to know the answer ruining the post with pointless, no good, Google links so I spend the next few days working it out. This post is
going the same way as the rest unfortunately.
So, at the end of the day I won't be using a ListView
Mar 10, 2014 01:03 AM|anuj_koundal|LINK
Have you seen this article?
Mar 10, 2014 05:42 PM|crouchie2004|LINK
That link was either the first or the second one I viewed before writing the post. If you read what I originally wrote you will know it isn't what I asked for