Paging using System;
Using System.Collections;
Using System.Configuration;
Using System.ComponentModel;
Using System.Data;
Using System.Data.SqlClient;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Namespace cj168. Web
{
<summary>
Summary description for search.
</summary>
public class Search:System.Web.UI.Page
protected System.Web.UI.WebControls.LinkButton lbnprevpage;
protected System.Web.UI.WebControls.LinkButton lbnnextpage;
String Txtsearch;
int pagesize,recordcount,pagecount,currentpage;
Public Search ()
{
Page.Init + = new System.EventHandler (Page_Init);
}
private void Page_Load (object sender, System.EventArgs e)
{
Put user code to initialize the page here
Txtsearch = request.params["Txtsearch"];
if (Txtsearch!= null)
{Txtsearch = Txtsearch.replace ("'", "");
Lbltxtsearch.text = Txtsearch;
Set pagesize
PageSize = 10;
Calculate how many records are in total
RecordCount = Calculaterecord ();
Lblrecordcount.text = Recordcount.tostring ();
Calculate how many pages are in total
PageCount = recordcount/pagesize;
if (recordcount%pagesize > 0)
PageCount = PageCount + 1;
Lblpagecount.text = Pagecount.tostring ();
viewstate["PageCount"] = PageCount;
}
}
}
Calculate how many records are in total
public int Calculaterecord ()
{
cj168. Dataaccess.magsdb dosearch = new cj168. Dataaccess.magsdb ();
Return Dosearch.getsearchresultcount (Txtsearch);
}
void Dosearch ()
{
int StartIndex;
int Fromitem, Toitem;
Set the start address of the import
StartIndex = currentpage*pagesize;
string cmd = E.commandname;
Judge Cmd to determine the direction of page flipping
Switch (CMD)
{
Case "Next":
if (currentpage< (PageCount-1)) currentpage++;
Break
Case "Prev":
if (currentpage>0) currentpage--;
Break
}
viewstate["PageIndex"] = currentpage;
Dosearch ();
}
private void Page_Init (object sender, EventArgs e)
{
//
Codegen:this the call are required by the ASP.net Web Form Designer.
//
InitializeComponent ();
}
#region Web Form Designer generated code
<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service