Pagination | control | source code using System;
Using System.IO;
Using System.Drawing;
Using System.Data;
Using System.Data.SqlClient;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.ComponentModel;
Namespace Pager
{
?///
?///Coolpager's summary description.
?///
? public enum SortType
? {
?? Asc=0,desc=1
?};
? public enum Iscount
? {
?? Noreturnrecordcount=0,returnrecordcount
?};
? [Defaultproperty ("CopyRight"),
?? ToolBoxData ("<{0}:coolpager runat=server>")]
? public class Coolpager:system.web.ui.webcontrols.webcontrol,inamingcontainer
? {?
?? protected int recordcount=0;
?? protected control _controltopaginate;
?? protected PagedDataSource _datasource;
?? [Bindable (True),
??? Category ("appearance"),
??? DefaultValue ("")]
?? public string CopyRight
?? {
??? Get
??? {
???? Return "All rights reserved: A bird in Qianshan";
???}
??}
?? Connection string
?? [Description ("Data source connection string"), DefaultValue ("")]
?? public string connectionString
?? {
??? Get
??? {
???? Object obj = viewstate["connectionString"];
???? Return (obj==null)? String.Empty:obj. ToString ();
???}
??? Set
??? {
???? viewstate["ConnectionString"]=value;
???}
??}
?? Controls that display pagination
?? [Description ("Controls to display pagination"), DefaultValue ("")]
?? public string ControlToPaginate
?? {
??? Get
??? {
???? Object obj=viewstate["ControlToPaginate"];
???? Return (obj==null)? String.Empty:obj. ToString ();
???}
??? Set
??? {
???? viewstate["ControlToPaginate"]=value;
???}
??}
?? Table name
?? [Description ("Query table name"), DefaultValue ("")]
?? public string TableName
?? {
??? Get
??? {
???? Object obj=viewstate["TableName"];
???? Return (obj==null)? String.Empty:obj. ToString ();
???}
??? Set
??? {
???? viewstate["TableName"]=value;
???}
??}
?? Sort Field Name
?? [Description ("Sort Fields"), DefaultValue ("")]
?? public string FieldName
?? {
??? Get
??? {
???? Object obj=viewstate["FieldName"];
???? Return (obj==null)? String.Empty:obj. ToString ();
???}
??? Set
??? {
???? viewstate["FieldName"]=value;
???}
??}
?? Show number of records per page
?? [Description (Number of records per page), DefaultValue ("")]
?? public int PageSize
?? {
??? Get
??? {
???? Object obj=viewstate["PageSize"];
???? Return (obj==null) 15:convert.toint32 (obj);
???}
??? Set
??? {
???? viewstate["PageSize"]=value;
???}
??}
?? Page
?? [Description ("current page number"), DefaultValue ("")]
?? public int PageIndex
?? {
??? Get
??? {
???? Object obj=viewstate["PageIndex"];
???? Return (obj==null) 1:convert.toint32 (obj);
???}
??? Set
??? {
???? viewstate["PageIndex"]=value;
???}
??}
?? Whether to return the total number of records
?? [Description ("returns Total Records"), DefaultValue ("")]
?? Public Iscount Iscount
?? {
??? Get
??? {
???? return iscount.returnrecordcount;
???}
??}
?? Sort Type
?? [Description ("Sort Type"), DefaultValue ("")]
?? Public SortType SortType
?? {
??? Get
??? {
???? Object obj=viewstate["SortType"];
???? Return (obj==null)? SORTTYPE.ASC: (sorttype) obj;
???}
??? Set
??? {
???? viewstate["SortType"]=value;
???}
??}
?? WHERE clause
?? [Description ("Where clause, without where"), DefaultValue ("")]
?? public string Where
?? {
??? Get
??? {
???? Object obj=viewstate["Where"];
???? Return (obj==null)? String.Empty:obj. ToString ();
???}
??? Set
??? {
???? viewstate["Where"]=value;
???}
??}
?? [Description ("Show number of navigation numbers"), DefaultValue ("")]
?? public int Showpagenumber
?? {
??? Get
??? {
???? Object obj=viewstate["Showpagenumber"];
???? Return (obj==null) 10:convert.toint32 (obj);
???}
??? Set
??? {
???? viewstate["Showpagenumber"]=value;
???}
??}
?? [Description ("Start Page"), DefaultValue ("")]
?? public int Pagestart
?? {
??? Get
??? {
???? Object obj=viewstate["Pagestart"];
???? Return (obj==null) 1:convert.toint32 (obj);
???}
??? Set
??? {
???? viewstate["Pagestart"]=value;
???}
??}
?? [Description ("Total pages, automatically generated"), DefaultValue ("")]
?? public int PageCount
?? {
??? Get
??? {
???? Object obj=viewstate["PageCount"];
???? Return (obj==null) 1:convert.toint32 (obj);
???}
??? Set
??? {
???? viewstate["PageCount"]=value;
???}
??}
?? ///
?? Renders this control to the specified output parameter.
?? ///
?? The HTML writer to write to
?? protected override void Render (HtmlTextWriter output)
?? {
??? if (Page.enableviewstate==false)
???? Page.enableviewstate=true;
??? if (site!=null && site.designmode)
???? if (! Page.IsPostBack)
???? CreateChildControls ();
??? Base. Render (output);
??}
?? public override void DataBind ()
?? {
??? Base. DataBind ();
??? childcontrolscreated = false;
??? if (controltopaginate = "")
???? Return
??? _controltopaginate = Page.findcontrol (controltopaginate);
??? if (_controltopaginate = null)
???? Return
??? if (!) ( _controltopaginate is BaseDataList | | _controltopaginate is ListControl))
???? Return
??? Bind data to the buddy control
??? BaseDataList Basedatalistcontrol = null;
??? ListControl ListControl = null;
??? if (_controltopaginate is basedatalist)
??? {
???? Basedatalistcontrol = (basedatalist) _controltopaginate;
???? Basedatalistcontrol.datasource = _datasource;
???? Basedatalistcontrol.databind ();
???? Return
???}
??? if (_controltopaginate is ListControl)
??? {
???? ListControl = (ListControl) _controltopaginate;
???? ListControl.Items.Clear ();
???? Listcontrol.datasource = _datasource;
???? Listcontrol.databind ();
???? Return
???}
??}
?? private void Fetchdata ()
?? {
??? SqlConnection cn=new SqlConnection (ConnectionString);
??? SqlCommand cm=new SqlCommand ();
??? Cm. CONNECTION=CN;
??? Cm. Connection.Open ();
??? Cm.commandtext= "Getrecordfrompage";
??? Cm.commandtype=commandtype.storedprocedure;
??? Cm. Parameters.Add ("@tblName", sqldbtype.nvarchar,255);
??? Cm. Parameters.Add ("@fldName", sqldbtype.nvarchar,255);
??? Cm. Parameters.Add ("@PageSize", SqlDbType.Int);
??? Cm. Parameters.Add ("@PageIndex", SqlDbType.Int);
??? Cm. Parameters.Add ("@isCount", sqldbtype.bit);
??? Cm. Parameters.Add ("@OrderType", sqldbtype.bit);
??? Cm. Parameters.Add ("@strWhere", sqldbtype.nvarchar,1000);
??? Cm. parameters["@tblName"]. Value=tablename;
??? Cm. parameters["@fldName"]. Value=fieldname;
??? Cm. parameters["@PageSize"]. Value=pagesize;
??? Cm. parameters["@PageIndex"]. Value=pageindex;
??? Cm. parameters["@isCount"]. value=0;
??? Cm. parameters["@OrderType"]. Value=sorttype;
??? Cm. parameters["@strWhere"]. Value=where;
??? SqlDataAdapter adapter = new SqlDataAdapter (cm);
??? DataTable DTB = new DataTable ();
??? Adapter. Fill (DTB);
??? Cm. parameters["@isCount"]. Value=iscount;
??? recordcount= (int) cm. ExecuteScalar ();
??? pagecount= (int) math.ceiling (double) recordcount/pagesize);
??? Cm. Connection.close ();
??? Cm. Dispose ();
??? cn. Dispose ();
??? Adapter. Dispose ();
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.