Namespace album
{
Using System;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
<summary>
A summary description of UC.
</summary>
public class AutoPage:System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.HyperLink Hpl_first;
protected System.Web.UI.WebControls.HyperLink Hpl_prev;
protected System.Web.UI.WebControls.HyperLink Hpl_next;
protected System.Web.UI.WebControls.Label lb_currentpage;
protected System.Web.UI.WebControls.Label Lb_pagecount;
protected System.Web.UI.WebControls.HyperLink hpl_last;
public int pagesize;
public string Pagep;
protected System.Web.UI.WebControls.TextBox txb_page;
protected System.Web.UI.WebControls.Label Lb_url;
protected System.Web.UI.WebControls.Label Lb_itemcount;
public string URL;
protected System.Web.UI.WebControls.Label lb_params;
protected System.Web.UI.WebControls.ImageButton Btn_go;
public string Params;
Public PagedDataSource DataBind (DataTable DT)
{
Lb_url. Text = URL;
Lb_params.text = Params;
Create a paging class
PagedDataSource objpage = new PagedDataSource ();
Setting up a data source
Objpage.datasource = dt. DefaultView;
Allow paging
Objpage.allowpaging = true;
Set the number of items to display per page
Objpage.pagesize = PageSize;
Set the index of the current page
int curpage=1;
Try
{
Curpage = Convert.ToInt32 (PAGEP);
if (curpage<1 curpage>objpage.pagecount)
{
Response.Redirect (url+ "page=1" +params);
}
}
Catch
{
Response.Redirect (url+ "page=1" +params);
}
Objpage.currentpageindex = CurPage-1;
Show status information
Lb_itemcount.text = dt. Rows.Count.ToString ();
Lb_currentpage.text = Curpage.tostring ();
Lb_pagecount.text =objpage.pagecount.tostring ();
If the current page is not home
if (!objpage.isfirstpage)
{
Hpl_prev.navigateurl=url + "? Page= "+ convert.tostring (CurPage-1) +params;
Hpl_first.navigateurl=url + "? Page=1 "+PARAMS;
}
If the current page is not the last page
if (!objpage.islastpage)
{
hpl_next.navigateurl=url+ "? Page= "+ convert.tostring (curpage+1) +params;
Hpl_last.navigateurl=url + "? Page= "+objpage.pagecount.tostring () +params;
}
return objpage;
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This.btn_go. Click + + new System.Web.UI.ImageClickEventHandler (This.btn_go_click);
This. Load + = new System.EventHandler (this. Page_Load);
Calls need to set a few parameters pagesize (number of data per page), PAGEP (passed the paging parameter), PARMP (other request.qureystring parameters), URL (page address)
The Datasource=autopage1.databind of the control (DataTable variable) is only required when binding
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