views:

144

answers:

2

Hi everyone,

I am using jquery ajax method to get data from a web method and present data using DOM(similar to that of google search results).B'coz the data returned from the web method is huge I want to paginate the results.For that I need to create buttons corresponding to the page numbers based on the no. of records the web method retrieves from the database.So I have taken a div on the page.In the web method ,as soon as I can find the number of records obtained from the database,I want to create the buttons and add to this div and display 10 records per page.As far as I know, it is not possible to access anything that is placed on the asp.net page from Web method.In that case how do I paginate the results?

Please help.

A: 

Here is an alternative suggestion on how to handle this scenario:

  1. When the page loads determine how many records you will be returning.
  2. Divide this by how many records you want to show per page (10).
  3. Add paging controls based on how many pages you will have at 10 records per page.
  4. Only query the database for the 10 records you will be showing on a given page. If the data is extremely huge you will not want to load it all into memory anyways. This can be done with a method signature that accepts how many records per page and the the current page you are on.
Jon
Hi Jon,I am able to find the number of paging controls needed for displaying my data.My data is retrieved from the database using a web method and it is from different tables which have no relation.Basically I am retrieving data from these tables based on a condition and loading into generic lists and finally concatenating them to return to the Jquery ajax method.So how can it be possible to limit the results to a particular number,as I am using multiple strored procs?and how do I add the paging controls to asp.net page b'coz I do not know how many of them I need in page load?
A: 

Hey,

if you are using JQuery ajax, you can recreate the UI on the client by doing statements like:

$("<input/>").attr("type", "button").click(function() { ..  }).appendTo("parentElementselector");

$.each(webmethodresults, function(i, item) {
     //Create UI here using approach illustrated above
});

And programmatically recreate for each page.

EDIT Or find a third party table control that you can bind to on the client side. MS AJAX 4 has some client-side JS components to do this or there are some JQuery ones... but either way, if using JQuery to stream via AJAX, you have to create on the client.

Brian
Sorry Brian,I am not clear with the above statements.Could you explain me with an example please?
Yes, you can use JQuery to build the paged UI that you desire. That's the ony way if you are using JQuery to stream results to you in JSON format. Either build the UI yourself or use a third party component, or the MS AJAX 4 client-side controls.
Brian