Pagination control webpager [ZT]

Source: Internet
Author: User

Click here to download the DLL file> webpager. dll.
1. webpager. CS

Using system;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. componentmodel;

[Assembly: tagprefix ("webpager", "WP")]
namespace Xiaoqiao. controls. webpager
{< br> Public Delegate void webpagereventhandler (Object sender, eventargs E);
///


/// abstract description of webpager.
//
[defaultproperty ("currentpageindex")]
[toolboxdata ("<{0 }: webpagercontrol runat = Server> ")]
[designer (" Xiaoqiao. controls. webpager. webpagerdesigner ")]
[parsechildren (false)]
public class webpagercontrol: webcontrol, inamingcontainer, ipostbackeventhandler
{< br> int m_currentpageindex = 0;
int m_pagecount = 0;
int m_pagesize = 1;
int m_recordcount = 0;
int m_navnums = 10;
system. drawing. color m_currentpagenumcolor = system. drawing. color. red;
system. collections. specialized. namevaluecollection _ AA;

String m_firstpagetext = "| & lt ;";
String m_prevpagetext = "& lt ;";
String m_nextpagetext = "& gt ;";
String m_lastpagetext = "& gt; | ";

// Define event proxy
Public event webpagereventhandler pagechange;
Public webpagercontrol ()
{
}
Protected override void render (system. Web. UI. htmltextwriter writer)
{
If (m_pagecount = 0)
{
Base. Render (writer );
Return;
}
Int n = m_navnums;
Int r = m_currentpageindex % N;
Int startindex = (m_CurrentPageIndex-r)/n * N;
Int endindex = startindex + n-1;

If (endindex> = m_pagecount)
Endindex = m_PageCount-1;

If (m_pagecount = 1 | m_currentpageindex = 0)
{
Writer. Write (m_firstpagetext );
Writer. Write ("& nbsp ;");
Writer. Write (m_prevpagetext );
Writer. Write ("& nbsp ;");
}
Else
{
Writer. addattribute (htmltextwriterattribute. href, "javascript:" + Page. getpostbackeventreference (this, "0 "));
Writer. renderbegintag (htmltextwritertag. );
Writer. Write (m_firstpagetext );
Writer. renderendtag ();
Writer. Write ("& nbsp ;");
Writer. addattribute (htmltextwriterattribute. href, "javascript:" + Page. getpostbackeventreference (this, (m_CurrentPageIndex-1). tostring ()));
Writer. renderbegintag (htmltextwritertag. );
Writer. Write (m_prevpagetext );
Writer. renderendtag ();
Writer. Write ("& nbsp ;");
}

For (INT I = startindex; I <= endindex; I ++)
{
String S = I. tostring ();
If (m_currentpageindex = I)
{
Writer. Write ("[" + (I + 1). tostring () + "]");
Writer. Write ("& nbsp ;");
}
Else
{
Writer. addattribute (htmltextwriterattribute. href, "javascript:" + Page. getpostbackeventreference (this, s ));
Writer. renderbegintag (htmltextwritertag. );
Writer. Write ("[" + (I + 1). tostring () + "]");
Writer. renderendtag ();
Writer. Write ("& nbsp ;");
}
}

If (m_pagecount = 1 | m_currentpageindex = (m_PageCount-1 ))
{
Writer. Write (m_nextpagetext );
Writer. Write ("& nbsp ;");
Writer. Write (m_lastpagetext );
}
Else
{
Writer. addattribute (htmltextwriterattribute. href, "javascript:" + Page. getpostbackeventreference (this, (m_currentpageindex + 1). tostring ()));
Writer. renderbegintag (htmltextwritertag. );
Writer. Write (m_nextpagetext );
Writer. renderendtag ();
Writer. Write ("& nbsp ;");
Writer. addattribute (htmltextwriterattribute. href, "javascript:" + Page. getpostbackeventreference (this, (m_PageCount-1). tostring ()));
Writer. renderbegintag (htmltextwritertag. );
Writer. Write (m_lastpagetext );
Writer. renderendtag ();
}

String inputid = This. clientid + "_ pagenum ";
Writer. addattribute (htmltextwriterattribute. type, "text ");
Writer. addattribute (htmltextwriterattribute. Size, "3 ");
Writer. addattrid (htmltextwriterattribute. ID, inputid );
Writer. addattribute (htmltextwriterattribute. Value, (m_currentpageindex + 1). tostring ());
Writer. renderbegintag (htmltextwritertag. Input );
Writer. renderendtag ();
Writer. addattripage (htmltextwriterattribute. onclick, "javascript:" + this. clientid + "_ gotopage ();");
Writer. addattribute (htmltextwriterattribute. type, "button ");
Writer. addattribute (htmltextwriterattribute. value, "go ");
Writer. renderbegintag (htmltextwritertag. Input );
Writer. renderendtag ();

Base. Render (writer );
}

Private void onpagechange (Object sender, eventargs E)
{
This. viewstate ["currentpageindex"] = m_currentpageindex;
If (pagechange! = NULL)
Pagechange (sender, e );
}

Protected override void onload (eventargs E)
{
Object state;

State = This. viewstate ["currentpageindex"];
If (State! = NULL)
M_currentpageindex = convert. toint32 (State );

State = This. viewstate ["recordcount"];
If (State! = NULL)
This. recordcount = convert. toint32 (State );

string inputid = This. clientid + "_ pagenum";
string scriptkey = "webpager_script";
If (! Page. isclientscriptblockregistered (scriptkey)
{< br> string script = "";
page. registerclientscriptblock (scriptkey, script);
}

Base. onload (E );
}

Public int currentpageindex
{
Get {return m_currentpageindex ;}
Set {m_currentpageindex = value ;}
}
Public int recordcount
{
Get
{
Return m_recordcount;
}
Set
{
Int I = value;
This. viewstate ["recordcount"] = I;
M_pagecount = getpages (I, m_pagesize );
M_recordcount = I;
}
}
Public int pagesize
{
Get
{
Return m_pagesize;
}
Set
{
Int I = value;
If (I> 0)
{
M_pagecount = getpages (m_recordcount, I );
M_pagesize = I;
}
Else
Throw (new exception ("pagesize must be greater than zero "));
}
}
Private int getpages (INT total, int pagesize)
{
Int I = total;
Int T;
If (I % pagesize) = 0)
T = I/pagesize;
Else
T = (INT) (I-I % pagesize)/pagesize + 1;
Return T;
}

Public int navnums
{
Get
{
Return m_navnums;
}
Set
{
Int I = value;
If (I> 0)
M_navnums = value;
}
}
Public String firstpagetext
{
Get
{
Return m_firstpagetext;
}
Set
{
M_firstpagetext = value;
}
}
Public String prevpagetext
{
Get
{
Return m_prevpagetext;
}
Set
{
M_prevpagetext = value;
}
}
Public String nextpagetext
{
Get
{
Return m_nextpagetext;
}
Set
{
M_nextpagetext = value;
}
}
Public String lastpagetext
{
Get
{
Return m_lastpagetext;
}
Set
{
M_lastpagetext = value;
}
}
Public System. Drawing. Color currentpagenumcolor
{
Get
{
Return m_currentpagenumcolor;
}
Set
{
M_currentpagenumcolor = value;
}
}

Public System. Collections. Specialized. namevaluecollection AA
{
Get {return _ AA ;}
Set {_ AA = value ;}
}

# Region ipostbackeventhandler Member

Public void raisepostbackevent (string eventargument)
{
// Todo: Add webpagercontrol. raisepostbackevent implementation
Currentpageindex = int. parse (eventargument );
Onpagechange (this, null );
}

# Endregion
}
}

2. webpagerdesigner. CS

Using system;
Using system. Globalization;

namespace Xiaoqiao. Controls. webpager
{< br> ///


// abstract description of webpagerdesigner.
//
public class webpagerdesigner: system. web. UI. design. controldesigner
{< br> Public webpagerdesigner ()
{< BR >}< br> Public override string getdesigntimehtml ()
{< br> webpagercontrol ocontrol = (webpagercontrol) component;
return string. format (cultureinfo. invariantculture,
"
webpagercontrol-{2}
",
ocontrol. width,
ocontrol. height,
ocontrol. ID);
}< BR >}

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.