Friendly paging of large data

  • Thread starter Thread starter Duncan Welch
  • Start date Start date
D

Duncan Welch

I am in the process of developing a site that will, on completion, be quite
high profile. I have successfully used the Datagrid to display paged data
from a database of around 10k records, but the standard paging techniques
use a linkbutton, which runs a small piece of client-side javascript.

To my understanding, this means that when I get "spidered" by a search
engine, it won't follow the javascript links, thereby my database won't get
indexed.

Has anyone seen an example whereby a) I'm using standard HTML links, and b)
I'm not loading all 10k records into a dataset every time someone hits the
server? Even classic ASP had it's objRecordset.PageSize and
objRecordset.AbsolutePage

Thanks in advance.
 
Hi Duncam,

You can do the same thing in ASP.NET :)

The datagrid have a PageSize and a CurrentPageIndex properties, that you can
use for that matter.

This is what I would do:
1- Read the dataset and keep it in memory on a session variable, ASP.NET has
no thread affinity ( I don't know if that is the correct spelling ; )
therefore you are no compromising the performance of the app.

2- Set the PageSize as needed.

3- Now setting the CurrentPageIndex is the core thing, if you want to get
spider then you need to use GET instead of POST , later you will see how
you can get this from the HTML code using links.
in the Load event you should do something like this:

if ( Request["CurrentPage"]!="" )
CurrentPageIndex = Convert.ToInt32( Request["CurrentPage"] );
else
CurrentPageIndex = 0;

datagrid.DataBind(); /// You have to rebind it after changing the page !!!



this is ALL the code you need in the server side to get to the correct page,
now how to get to the correct page?
Very easy in fact :)
1- Disable the grid default paging , I think remember this is done by
setting the ShowFooter to false
2- Include two asp:LinkButtons in the page these will work like the previous
and next
I will show you only the next, the previous is similar
<asp:HyperLink NavigateUrl=<%#NextPageUrl()%>"
Visible="<%#ExistNextPage()%>" ></asp:HyperLink>

This is the code for the methods:
protected string NextPageUrl()
{
return "pagename.aspx?CurrentPage=" + Convert.ToString(
datagrid.CurrentPageIndex + 1);
}
protected bool ExistNextPage()
{
return datagrid.CurrentPageIndex< datagrid.PageCount;
}


This should solve your problem, but please remember that I just wrote the
code above, I haven't test it and you may have to fine tuning it.

Hope this help,
 
Back
Top