Been searching for hours on the Internet for a code sample and they all use a Gridview, which is not what I am interested in using.
I am using a ListView and a DataPager control together (rather than a Gridview) with a textbox and a button in VB.NET 2012 on Framework 4.5
When the page loads I wish to have all rows returned but if someone wishes to filter the results I wish to filter them (page size 20).
Just messing around with some code I tried I can get it to filter but clicking page 2... on the paging control returns page 2 of the entire table rather than page 2 of the filtered results.
What code, I hear you say? Just do a simple 'select' statement to populate a datatable
Normally in pre_render you bind the data but if there is something entered into a textbox (filtered) then to use that info instead
Also wish to verify the input into the textbox is numeric and also guard against sql injection attacks. Don't suppose the injection part would be an issue if just filtering results
Any ideas?
Please click 'Mark as Answer' if my reply helped
Homepage | YouTube Channel | Post code, not links
The code you posted is the code I have been using but in VB.NET obviously. It's the rebinding of the code which is the issue because a standard rebind rebinds the entire table rather than the filtered results, hence my original question in the VB.NET forum.
Therefore, I need a way to rebind the filtered results in the DataView. I don't want to keep contacting the database with a new select statement on each request but to filter and page the original datatable
The link you provided is part of code that can be found in millions of sites all over the Internet but it's not what I wanted and that was specified in my original question. Not one website have I found in over 9 hours of checking comes close to the code
which I am originally asking about and that was the reason for my main question and posting it in the VB.NET forum. Was hoping that I would get a reply in VB not C#, too. That's why it's called a VB.NET forum.
Do you have any idea how to rebind a filtered datatable so the results can be paged in VB.NET? Google doesn't seem to have the answer but a VB.NET coder might.
Please click 'Mark as Answer' if my reply helped
Homepage | YouTube Channel | Post code, not links
crouchie2004
Member
497 Points
306 Posts
ListView Paging & Filtering
Feb 27, 2013 07:40 PM|LINK
Hi,
Been searching for hours on the Internet for a code sample and they all use a Gridview, which is not what I am interested in using.
I am using a ListView and a DataPager control together (rather than a Gridview) with a textbox and a button in VB.NET 2012 on Framework 4.5
When the page loads I wish to have all rows returned but if someone wishes to filter the results I wish to filter them (page size 20).
Just messing around with some code I tried I can get it to filter but clicking page 2... on the paging control returns page 2 of the entire table rather than page 2 of the filtered results.
What code, I hear you say? Just do a simple 'select' statement to populate a datatable
Normally in pre_render you bind the data but if there is something entered into a textbox (filtered) then to use that info instead
Also wish to verify the input into the textbox is numeric and also guard against sql injection attacks. Don't suppose the injection part would be an issue if just filtering results
Any ideas?
Homepage | YouTube Channel | Post code,
not linksJason Duncan
Member
413 Points
222 Posts
Re: ListView Paging & Filtering
Feb 28, 2013 03:14 AM|LINK
You may need to rebind the control each time there is a page event change -- based on the filter settings.
http://blog-rat.blogspot.com/2011/04/using-datapager-in-listview.html
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { ListView lv = sender as ListView; DataPager pager = lv.FindControl("DataPage1") as DataPager; pager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); BindData(); // set DataSource to ListView and call DataBind() of ListView }crouchie2004
Member
497 Points
306 Posts
Re: ListView Paging & Filtering
Feb 28, 2013 02:32 PM|LINK
Hi Jason,
Thanks for the reply
The code you posted is the code I have been using but in VB.NET obviously. It's the rebinding of the code which is the issue because a standard rebind rebinds the entire table rather than the filtered results, hence my original question in the VB.NET forum. Therefore, I need a way to rebind the filtered results in the DataView. I don't want to keep contacting the database with a new select statement on each request but to filter and page the original datatable
The link you provided is part of code that can be found in millions of sites all over the Internet but it's not what I wanted and that was specified in my original question. Not one website have I found in over 9 hours of checking comes close to the code which I am originally asking about and that was the reason for my main question and posting it in the VB.NET forum. Was hoping that I would get a reply in VB not C#, too. That's why it's called a VB.NET forum.
Do you have any idea how to rebind a filtered datatable so the results can be paged in VB.NET? Google doesn't seem to have the answer but a VB.NET coder might.
Homepage | YouTube Channel | Post code,
not links