JS Code
var Displaycount;
var Getdataurl;
var Booktableid;
var currentindex;
var PageCount;
var Linkclass;
var fields;
function Initpagebar (DC, Gdu, BTID,PC,LC) {
Displaycount = DC;
Getdataurl = Gdu;
Booktableid = Btid;
Currentindex = 1;
PageCount = PC;
Linkclass = "." +LC;
$ (Linkclass). Click (getpage);
}
function Getpagebyid (ID) {
$ ("#CI"). Val (id);
var surl = getdataurl+ "? pageindex=" + ID;
$.ajax ({
Url:surl,
Type: "Get",
DataType: "JSON",
timeout:1000,
Success:showresult
}
);
}
function GetPage () {
Getpagebyid ($ (this). Get (0). ID);
}
function Showresult (Result) {
for (i = 1; I <= result. Data.length; i++) {
var id = "#" + Booktableid + "tr:nth-child (" + i + ")";
obj = result. DATA[I-1];
for (var key in obj) {
CTL = $ (ID). FIND ("." + key);
if (Ctl.length > 0) {
Ctl.get (0). InnerHTML = Obj[key];
}
}
}
$ (Linkclass). Each (function (index) {
var i, B, E;
if (result. CurrentPageIndex <= Displaycount) {
b = 1;
E = (displaycount + 1) * 2;
i = index-2 + 1;
}
else if (result. CurrentPageIndex > Pagecount-displaycount) {
b = Pagecount-displaycount * 2;
e = PageCount;
i = Pagecount-displaycount * 2 + index-2;
}
else {
i = result. Currentpageindex-displaycount + index-2;
b = result. currentpageindex-displaycount-1;
E = result. CurrentPageIndex + Displaycount + 1;
}
if ($ (this). Get (0). id = = $ (this). Text ()) {
$ (this). text (i);
}
else if (index = = 1) {
if (b <= 1) {
$ (this). Get (0). id = 1;
}
else {
$ (this). Get (0). id = b-1;
}
}
else if (index = = Displaycount * 2 + 3) {
$ (this). Get (0). id = e;
}
$ (this). attr ("href", "#");
if ((i >= b) && (i <= e)) {
$ (this). Get (0). id = i;
}
if ($ (this). Text = result. CurrentPageIndex) {
$ (this). Removeattr ("href");
}
});
Currentindex = result. CurrentPageIndex;
}
HTML code
<form runat= "Server" id= "Form1" >
<div>
<asp Tutorial: Repeater id= "Rptbooks" runat= "Server" >
<HeaderTemplate>
<table id= "Books" width= "90%" cellspacing= "0" style= "font-size:12px;" >
<tr>
<th>
Title
</th>
<th>
Author
</th>
<th>
Category
</th>
<th width= "30px" >
</th>
<th width= "30px" >
</th>
</tr>
<tbody id= "Data" >
<tr>
</HeaderTemplate>
<ItemTemplate>
<TD class= "Title" >
<%# Eval ("Title")%>
</td>
<TD class= "Author" >
<%# Eval ("Author")%>
</td>
<TD class= "CategoryName" >
<%# Eval ("Categories.name")%>
</td>
<td>
<a href= "#" Id= ' <%# Eval ("id")%> ' class= ' delbook ' > Delete </a>
</td>
<td>
<a href= ' bookdetail/<%# Eval ("Id")%> ' class= ' details ' > detail </a>
</td>
</ItemTemplate>
<SeparatorTemplate>
</tr><tr>
</SeparatorTemplate>
<FooterTemplate>
</tr></tbody>
<tr>
<TD colspan= "3" >
<cc1:pagebar id= "PageBar1" runat= "Server" pagecount= "5" displaycount= "1" pageindex=
<input type= "text" id = "CI"/>
</td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
Ajax return Data
{"Data": [{] Title: "C #. NET program Design--Foreign computer Science classics textbook "," CategoryName ":". NET "," Author ":" Bradley (bradley,j.c.), Milspo (millspaugh,a.c.), Tian Wang Studio translation "," Id " : 5392},{"title": "c#2.0(Treasure Book" (with Disk), "CategoryName": "C C + + VC + +", "Author": "Zhangli Editor", "Id": 5027},{"title": "C#2.0 complete self-study Manual ( Attached CD) "," CategoryName ":" C C + + VC + + "," Author ":" Zhangli, etc. "," Id ": 5081},{" Title ":" C#2005 Database Tutorial Programming Classic course "," CategoryName ":" C c+ + VC + +, "Author": "(US) Wharton (Karli Watton), Chen Qiuping translation", "Id": 4983},{"Title": "C # Programming Course--Computer Basic Course series", "CategoryName": C C + + VC VC + +, "Author": "Zheng Achi, Liang Jingdong editor-in-chief", "Id": 5127},{"Title": "C # Programmer's Reference manual", "CategoryName": "C C + + VC + +", "Author": "Grant Palmer , Kang Bo translation "," "Id": 5132},{"Title": "C # and. NET core technology--developer Professional and Technical series", "CategoryName": "C C + + VC + +", "Author": "(US) Perry (PERRY,S.C.), Xiaobin, "id": 5104},{"Title": "C # Foundation and example tutorial (with a CD-ROM disc)", "CategoryName": "C C + + VC + +", "Author": "Shunchunqiang Authoring", "id": 5071},{" Title ":" C # software project development throughout the analysis, "CategoryName": "C C + + VC + +", "Author": "(DE) Hom, (Germany) Kruger, (DE) Spuda, Xue Xing Tao, Xianqing Yong translation", "Id": 5034},{"Title" : "C # Design pattern--Development Master Series", "CategoryName": "C C + + VC + +", "Author": "(the United StatesMascow, Yeng translation "," Id ": 4954}]," CurrentPageIndex ":" PageCount ": 1074}
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Linq;
Using System.Text;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Reflection;
Using System.IO;
[Assembly:webresource ("Pagebarjs.js", "Application/x-javascript Tutorial")]
Namespace Hawkon.control {
[Defaultproperty ("Text")]
[ToolBoxData ("<{0}:P agebar runat=server></{0}:P agebar>")]
public class Pagebar:webcontrol {
[Bindable (True)]
[Category ("Data")]
[DefaultValue ("1")]
[Localizable (true)]
public int PageIndex {
get {
return pageIndex;
}
set {
PageIndex = value;
}
}
private int pageIndex;
[Bindable (True)]
[Category ("Data")]
[DefaultValue ("1")]
[Localizable (true)]
public int PageCount {
get {
return PageCount;
}
set {
PageCount = value;
}
}
private int PageCount;
[Bindable (True)]
[Category ("Data")]
[DefaultValue ("5")]
[Localizable (true)]
public int Displaycount {
get {
return displaycount;
}
set {
Displaycount = value;
}
}
private int displaycount;
protected override void RenderContents (HtmlTextWriter output) {
String html = "";
HTML + + Createa (1, "<<");
int b = 0, E = 0;
if (PageIndex <= displaycount) {
b = 1;
E = Displaycount * 2 + 1;
}
else if (PageIndex > Pagecount-displaycount) {
b = Pagecount-displaycount * 2;
e = PageCount;
}
else {
b = Pageindex-displaycount;
E = PageIndex + displaycount;
}
if (b <= 1) {
HTML + createa (1, "");
}
Else
HTML + createa (b-1, "");
for (int i = b; I <= e; i++) {
HTML + createa (i, i.tostring ());
}
HTML + + Createa (e + 1, "");
HTML + + Createa (PageCount, ">>");
html = string. Format ("<script src= ' {0} ' type= ' Text/javascript ' ></script>",
This. Page.ClientScript.GetWebResourceUrl (typeof (Pagebar), "jscript1.js"));
Output. Write (HTML);
}
private string Createa (int pageIndex, string text) {
if (PageIndex = = This.pageindex) {
return string. Format ("<a class=" PageA "title= ' page ' id = ' {0} ' >{1}</a>", pageIndex, text);
}
return string. Format ("<a class=" PageA "title= ' page ' href=" # "id=" {0} ">{1}</a>", PageIndex, text);
}
protected override void OnPreRender (EventArgs e) {
Base. OnPreRender (e);
String resourcename = "Pagebarjs.js";
String url = this. PAGE.CLIENTSCRIPT.GETWEBRESOURCEURL (this. GetType (), "pagebarjs.js");
String script = "<script src=" "+ httputility.htmlattributeencode (URL) +" "type=" Text/javascript "></script > ";
This. Page.ClientScript.RegisterClientScriptBlock (this. GetType (), resourcename, script, false);
Script = @ "<script type=" "Text/javascript" ">$ (document). Ready (function () {Initpagebar (5," "Booklistbypage" "," "Books" ",", "" PageA ""); </script> "; This. Page.ClientScript.RegisterClientScriptBlock (this. GetType (), "Ready", script);
}
protected override void Render (HtmlTextWriter writer) {
Base. Render (writer);
}
}
}