Common paging classes (without SQL, directly binding data)

Source: Internet
Author: User
Tags httpcontext
Pagination | data | Performing data paging has always been a headache, and many paging controls have been created. But I used a few of the controls, itself to execute SQL, poor support for stored procedures, in order to facilitate, especially write a common page class, using PagedDataSource to achieve datagrid,datalist,repeater paging. Complete the previous page, the next page,
The last page, the first page, the total number of pages, the current number of pages, jump these basic features.



Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;


Namespace Aspnetpager
{
///
Netpager-This class provides datagrid,datalist,repeater common paging---jierry 04-7-19
///
public class Netpager:System.Web.UI.Page
{
Private System.Web.UI.WebControls.DataGrid Datagrid=null;
Private System.Web.UI.WebControls.DataList Datalist=null;
Private System.Web.UI.WebControls.Repeater Repeater=null;
Private System.Web.UI.WebControls.HyperLink Lnknext;
Private System.Web.UI.WebControls.HyperLink Lnkprev;
Private System.Web.UI.WebControls.HyperLink lnkfist;
Private System.Web.UI.WebControls.HyperLink Lnklast;
Private System.Web.UI.WebControls.HyperLink Lnkjump;
Private System.Web.UI.WebControls.Label Pagenum;
Private System.Web.UI.WebControls.Label PageCount;
Private System.Web.UI.WebControls.DropDownList list;


Public Netpager ()
{
//
TODO: Add constructor logic here
//
}

Public System.Web.UI.WebControls.DataGrid DataGrid
{
Get
{
return This.datagrid;
}
Set
{
This.datagrid=value;
}
}

Public System.Web.UI.WebControls.DataList DataList
{
Get
{
return this.datalist;
}
Set
{
This.datalist=value;
}
}

Public System.Web.UI.WebControls.Repeater Repeater
{
Get
{
return this.repeater;
}
Set
{
This.repeater=value;
}
}


Public System.Web.UI.WebControls.HyperLink Lnkprev
{
Get
{
return this.lnkprev;
}
Set
{
This.lnkprev=value;
}
}

Public System.Web.UI.WebControls.HyperLink Lnknext
{
Get
{
return this.lnknext;
}
Set
{
This.lnknext=value;
}
}

Public System.Web.UI.WebControls.HyperLink Lnkfist
{
Get
{
return this.lnkfist;
}
Set
{
This.lnkfist=value;
}
}

Public System.Web.UI.WebControls.HyperLink Lnklast
{
Get
{
return this.lnklast;
}
Set
{
This.lnklast=value;
}
}

Public System.Web.UI.WebControls.HyperLink Lnkjump
{
Get
{
return this.lnkjump;
}
Set
{
This.lnkjump=value;
}
}

Public System.Web.UI.WebControls.Label Pagenum
{
Get
{
return this.pagenum;
}
Set
{
This.pagenum=value;
}
}

Public System.Web.UI.WebControls.Label PageCount
{
Get
{
return this.pagecount;
}
Set
{
This.pagecount=value;
}
}

Public System.Web.UI.WebControls.DropDownList List
{
Get
{
return this.list;
}
Set
{
This.list=value;
}
}


public void DataPage (DataSet ds,int pagenum)
{
PagedDataSource Objpds = new PagedDataSource ();
Objpds.allowpaging =true;
Display number per page
Objpds.pagesize =pagenum;
Specify the data source
Objpds.datasource = ds. Tables[0]. DefaultView;
int curpage;
Binding DropDownList Data
for (int i=1;i<=objpds.pagecount;i++)
{
THIS.LIST.ITEMS.ADD (i.ToString ());
}
This.list.Items.Insert (0,new ListItem ("page", ""));
Determine the current number of pages
if (system.web.httpcontext.current.request.params["Page"]!= null)
{
Curpage=convert.toint32 (system.web.httpcontext.current.request.params["Page"));

}
Else
{
curpage=1;
}

Objpds.currentpageindex = CurPage-1;


Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.