asp.net| Pagination | controls | page
First, create a class
public class navigation
{
private string _sitename, _siteurl;
Public navigation (String siteName, String siteurl)
{
_sitename = SiteName;
_siteurl = SiteURL;
}
public string SiteName {get {return _sitename;}}
public string SiteURL {get {return _siteurl;}}
}
Second, pagination
DbAccess mydb = new dbAccess ();
MyDB. SQLSTR = "SELECT count (BookID) as Totalid from Szhotline where bkcity= '" + bkcity + "' and atype=" + atype;
DataSet dstotal = mydb.readtable ("Szhotline");
int counttotal = Convert.ToInt32 (dstotal.tables["Szhotline"). rows[0]["Totalid"]. ToString ()); Total number of records
int totalpage = 0; Total pages
if (counttotal% perpage = 0)
Totalpage = Convert.ToInt16 (counttotal/perpage);
Else
Totalpage = Convert.ToInt16 (counttotal/perpage) + 1;
int Cp_n, cp_p;
if (Cur_page > 1)
Cp_p = cur_page-1;
Else
Cp_p = 1;
If (Cur_page < totalpage)
Cp_n = cur_page + 1;
else
Cp_n = totalpage;
Link_p.navigateurl = "szhotline.aspx?page_c=" + cp_p + "&bkcity=" + bkcity + "&atype=" + atype;
Link_n.navigateurl = "szhotline.aspx?page_c=" + cp_n + "&bkcity=" + bkcity + "&atype=" + atype;
list1.datatextfield= "SiteName";
list1.datavaluefield= "SiteURL";
ArrayList arr = new ArrayList ();
MyDB. SQLSTR = "SELECT top" + Perpage + "* FROM (select top" + perpage*convert.toint16 (cur_page) + "Bookid,bookname from Szh Otline where atype= "+ Atype +" and bkcity= ' "+ bkcity +" ' ORDER by BookID-desc "ORDER by bookid ASC"; The
DataSet myds = mydb.readtable ("Szhotline");
for (int i=0; I {
string bkname = myDS. tables["Szhotline"]. rows["BookName"]. ToString (). Trim ();
String bkurl = "szhotdet.aspx?bookid=" + myds. tables["Szhotline"]. rows["BookID"]. ToString (). Trim ();
Arr. ADD (new Navigation (Bkname, Bkurl));
}
List1.datasource = arr;
List1.itemsaslinks = true;
List1.databind ();
ActiveForm = list;
Description: Where dbaccess is a custom action database class, because the database is using Access. The paging of the M,n two parameters is adjusted by using the desc of select top N * FROM (SELECT * m) to the ORDER by id Desc.