A encapsulated CSS paging navigation bar

Source: Internet
Author: User

See http://blog.csdn.net/greystar/archive/2008/04/08/2260363.aspx for the effect

 

Page.css

# Channel-page
{
Height: 22px;
Margin: 5px auto;
Padding: 0px;
Text-align: center;
Line-Height: 20px;
Width: 500px;
}

# Channel-page ul # channel-page-show
{
Line-Height: 20px;
Margin: 0px auto;
List-style-type: none;

Padding: 0px;
Text-align: center;
Width: 100%;
Height: 22px;
}
# Channel-page ul # channel-page-show Li
{
Display: inline;
Float: left;
Width: 23px;
Padding: 0px 2px;
Margin: 2px 0px;
Height: 20px;
Text-align: center;

}
# Channel-page ul # channel-page-show Li
{
Border: solid 1px #999;
Display: block;
Font-weight: 700;
Font-size: 12px;
Width: 20px;
Color: #666;
Height: 20px;
Background-color: # FFF;
Text-align: center;
Text-Decoration: none;

}
# Channel-page ul # channel-page-show Li A: hover
{
Font-size: 20px;
Z-index: 100;
Width: 40px;
Line-Height: 40px;
Position: absolute;
Height: 40px;
Margin-top:-10px;
Margin-Right: 0px;
Margin-bottom: 0px;
Margin-left:-10px;
Background-color: # FFF;

}
# Channel-page ul # channel-page-show Li A. Page-select
{
Color: red;

}
# Channel-page ul # channel-page-show li # channel-page-count
{
Border: solid 1px #999;
Font-weight: 700;
Font-size: 12px;
Width: 50px;
Color: #666;
Height: 20px;
Line-Height: 20px;
Background-color: # FFF;
Text-align: center;
Text-Decoration: none;
Padding: 0px;
Margin: 2px 3px;
Float: left;

}

# Channel-page ul # channel-page-show li # channel-page-Form
{
Border: solid 1px #999;
Display: block;
Font-size: 12px;
Width: 60px;
Color: #666;
Float: left;
Background-color: # FFF;
Text-Decoration: none;
Padding: 0px;
Margin-Right: 1px;
Margin-left: 2px;
White-space: nowrap;
Vertical-align: middle;

}

# Channel-page-form input # pagenum
{
Width: 25px;
Float: left;
Border: solid 1px # FFF;
Vertical-align: middle;
Margin: 0px 0px;
Color: #666;
}
# Channel-page-form input # navbutton
{
 
Width: 25px;
Float: left;
Background-color: # FFF;
Font-size: 14px;
Border: 1px solid # FFF;
Color: #666;
Height: 20px;
}

 

The pagebar. CS code is as follows:

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. text;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Namespace finstone. Common. Control
{
[Defaultproperty ("text")]
[Toolboxdata ("<{0}: pagebar runat = Server> </{0}: pagebar>")]
Public class pagebar: webcontrol
{
Public pagebar (): Base (htmltextwritertag. Div ){

This. style. Add ("text-align", "center ");
This. style. Add ("margin", "2px auto ");


}
Int page = 1;
[Bindable (true)]
[Category ("appearance")]
[Defaultvalue ("")]
[Localizable (true)]
Public String text
{
Get
{
String S = (string) viewstate ["text"];
Return (S = NULL )? String. Empty: S );
}

Set
{
Viewstate ["text"] = value;
}
}
Protected override void onload (eventargs E)
{

Base. onload (E );
If (page. Request. querystring ["page"]! = NULL)
{
Currentpage = int. parse (page. Request. querystring ["page"]. tostring ());
}
Page = currentpage;
}
Protected override void onprerender (eventargs E)
{
String cssurl = This. Page. clientscript. getwebresourceurl (this. GetType (), "finstone.common.pagebar.css ");
Finstone. Common. Web. util. addcss (cssurl, this. Page );

Base. onprerender (E );
}

Protected override void rendercontents (htmltextwriter output)
{

Stringbuilder sb = new stringbuilder ();

Int num = 1;
Int allcount = allcount;
Int pagesize = pagesize;


Num = finstone. Common. Web. util. getpagecount (allcount, pagesize); // calculate the page size.

Int szpage = page;

SB. append ("<Div id =/" channel-page/"> ");
SB. append ("<ul id =/" channel-page-show/"> ");
SB. append ("<li id =/" channel-page-count/">" + Page + "/" + num + "</LI>"); // All pages
SB. append ("<li> <a target = '_ Self' href = '" + finstone. common. web. util. updateparam ("page", "1") + "'> & lt; </a> </LI>"); // page 1

If (szpage> 1)
{
SB. append ("<li> <a target = '_ Self' href = '" + finstone. common. web. util. updateparam ("page", (szpage-1 ). tostring () + "'> & lt; </a> </LI>"); // Previous Page
}

// Calculate the start page number and the last page number at most 10
Int startindex = 0;
Int endindex = 0;
If (szpage <= 10)
{
Startindex = 0;
Endindex = num <10? Num: 10;
}
Else
{
Startindex = szpage-5;
Endindex = num <szpage + 5? Num: szpage + 5;
}

For (INT I = startindex; I <= endindex-1; I ++)
{
Int szcontent = I + 1;
If (szcontent = page)
{
SB. append ("<li> <a class =/" Page-select/"'href = 'javascript: void (0 ); '> "+ szcontent +" </a> </LI> ");
}
Else
{
SB. append ("<li> <a target = '_ Self' href = '" + finstone. common. web. util. updateparam ("page", szcontent. tostring () + "'>" + szcontent + "</a> </LI> ");
}
}

If (szpage <num)
{
SB. append ("<li> <a target = '_ Self' href = '" + finstone. common. web. util. updateparam ("page", (szpage + 1 ). tostring () + "'> & gt; </a> </LI>"); // next page
}

SB. append ("<li> <a target = '_ Self' href = '" + finstone. common. web. util. updateparam ("page", num. tostring () + "'> & gt; </a> </LI>"); // the last page.

If (shownavbar)
{
String S = "";
SB. append ("<li id =/" channel-page-form/"> ");
String url = rebuildurl ();
SB. append ("<input name =/" pagenum/"type =/" text/"id =/" pagenum/"maxlength =/" 5/"> <input type = /" button/"id =/" navbutton/"value =/" Go/"onclick =/" Var intstr =/^ // D + $ /; if (intstr. test (pagenum. value) & pagenum. value <= "+ num +" & pagenum. value> = 1) {location. href = '"+ URL +"' + pagenum. value;}/"> </LI> ");

}

SB. append ("</ul> ");
SB. append ("</div> ");

Output. Write (sb. tostring ());
}

String rebuildurl ()
{
String url = This. Page. Request. currentexecutionfilepath + "? ";
If (this. Page. Request. querystring. Count> 0)
{

Foreach (string s in this. Page. Request. querystring. allkeys)
{
If (S. toupper ()! = "Page ")
{
URL + = S + "=" + Page. Request. querystring [s]. tostring () + "&";
}
}
// URL = URL. trimend ('&');

}

URL + = "page = ";

Return URL;
}
Public int allcount
{
Get
{
If (viewstate ["allcount"] = NULL)
Return 0;
Return (INT) viewstate ["allcount"];
}
Set
{
Viewstate ["allcount"] = value;
}
}
Public int currentpage
{
Get {
If (viewstate ["page"] = NULL)
Return 1;
Return (INT) viewstate ["page"];
}
Set {
Viewstate ["page"] = value;
}

}

Public int pagesize
{
Get {
If (viewstate ["pagesize"] = NULL)
Return 10;
Return (INT) viewstate ["pagesize"];

}
Set {
Viewstate ["pagesize"] = value;
}

}

Public bool shownavbar
{
Get
{
If (viewstate ["shownavbar"]! = NULL)
{
Return (bool) viewstate ["shownavbar"];
}
Else
Return false;

}
Set
{
Viewstate ["shownavbar"] = value;
}
}

}
}

Add the next line of code to assemblyinfo. CS.

[Assembly: webresource ("finstone.common.pagebar.css", "text/CSS")]

Otherwise, use the page.css file as the resource file,

You only need to set the attributes of allcount currentpage and pagesize.

 

Related Article

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.