国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET分頁組件學(xué)與用——教學(xué)篇(源代碼)

2024-07-10 12:57:31
字體:
供稿:網(wǎng)友
using system;

using system.web.ui;

using system.web.ui.webcontrols;

using system.componentmodel;



using system.text;



namespace nslzhpages

{



public class lzhpages : system.web.ui.webcontrols.webcontrol

{

private int _count;//每頁顯示的記錄條數(shù)

private int _currentpage;//當(dāng)前頁

private int _allcount;//所有記錄條數(shù)

private int _showpages;//顯示頁數(shù)



//以下腳本用于從文本框輸入頁碼

private const string scriptstring = "<script language='javascript'>/n" +

" function go(ctrl,max)/n" +

" {/n" +

" if(ctrl.value >= 1 && ctrl.value <= max)/n" +

" {/n" +

" var url;/n" +

" var index;/n" +

" url = location.href;/n" +

" index = url.indexof('?');/n" +

" if(index == -1)/n" +

" {/n" +

" }/n" +

" else/n" +

" {/n" +

" url = url.substring(0,index);/n" +

" }/n" +

" location.href = url + '?currentpage=' + ctrl.value;/n" +



" }/n" +

" else/n" +

" {/n" +

" alert('您輸入的頁碼必須是符合頁面要求的數(shù)字,最大值是:' + max);/n" +

" return false;/n" +

" }/n" +

" }/n" +

"</script>/n";





[defaultvalue(10),category("customer")]

public int count

{

set

{

if(value <= 0)

_count = 1;

else

_count = value;

}

get

{

return _count;

}

}



[defaultvalue(1),category("customer")]

public int currentpage

{

set

{

if(value < 0)

_currentpage = 1;

else

_currentpage = value;

}

get

{

return _currentpage;

}

}



[defaultvalue(1),category("customer")]

public int allcount

{

get

{

return _allcount;

}

set

{

if(_allcount < 0)

throw new exception("記錄總條數(shù)不能為負(fù)數(shù)");

else

_allcount = value;

}

}



[defaultvalue(1),category("customer")]

public int pages//總頁數(shù)

{

get

{

if(this._allcount % this._count > 0)

return ((int)this._allcount / this._count) + 1;

else

return ((int)this._allcount / this._count);

}

}



[defaultvalue(1),category("customer")]

public int showpages

{

set

{

if(value > 0)

_showpages = value;

else

_showpages = 9;

}

get

{

return _showpages;

}

}



protected override void render(htmltextwriter writer)

{

base.render (writer);



string leftinfo;

stringbuilder centerinfo = new stringbuilder();



//分頁條分三部分,leftinfo是最左邊的部分,用來顯示當(dāng)前頁/總頁數(shù),每頁顯示的記錄條數(shù)

leftinfo = "頁:" + this.currentpage.tostring() + "/" + this.pages.tostring() + "&nbsp;&nbsp;" + "每頁" + this.count.tostring() + "條" + "&nbsp;&nbsp;共" + this.allcount.tostring() + "條";



//中間的部分是分頁部分

int min;//要顯示的頁面數(shù)最小值

int max;//要顯示的頁面數(shù)最大值



if(this.currentpage > this.pages)//當(dāng)前頁必須小于最大頁

{

this.currentpage = this.pages;

}



if(this.currentpage % this.showpages == 0) //如果恰好整除

{

min = this.currentpage + 1;

max = this.currentpage + this.showpages ;

}

else if(this.currentpage % this.showpages == 1 && this.currentpage > this.showpages )

{

min = (((int)this.currentpage / this.showpages ) - 1) * this.showpages +1;

max = this.currentpage - 1;

}

else

{

min = ((int)this.currentpage / this.showpages) * this.showpages + 1;

max = (((int)this.currentpage / this.showpages) +1) * this.showpages;

}



string numberstr = "&nbsp;";//循環(huán)生成數(shù)字序列部分

string absurl;//url?左邊的部分

absurl = this.context.request.url.tostring();

if(absurl.indexof("?") == -1)

{

}

else

{

absurl = absurl.substring(0,absurl.indexof("?"));

}



for(int i = min ; i <= max ; i++)

{

if(i <= this.pages)//只有不大于最大頁才顯示

{

if(this.currentpage == i)//如果是當(dāng)前頁,用斜體和紅色顯示

{

numberstr = numberstr + "<a href=" + absurl + "?currentpage=" + i.tostring() + ">" + "<i style='color:red'>" + i.tostring() + "</i>" +"</a>" + "/n";

}

else

{

numberstr = numberstr + "<a href=" + absurl + "?currentpage=" + i.tostring() + ">" + i.tostring() +"</a>" + "/n";

}

}

}



//第一頁,上一頁,下一頁,最后一頁

string first,previous,next,last;

first = absurl + "?currentpage=1";

/////////

if(this.currentpage == 1)

previous = absurl + "?currentpage=1";

else

previous = absurl + "?currentpage=" + (this.currentpage - 1).tostring();

/////////

if(this.currentpage == this.pages)

next = absurl + "?currentpage=" + this.pages;

else

next = absurl + "?currentpage=" + (this.currentpage + 1).tostring();

/////////

last = absurl + "?currentpage=" + this.pages;



centerinfo.appendformat("<font face='webdings' style='font-size:14px'><a href={0}>7</a><a href={1}>3</a></font>{2}<font face='webdings' style='font-size:14px'><a href={3}>4</a><a href={4}>8</a></font>",first,previous,numberstr,next,last);



stringbuilder sb = new stringbuilder();//html字符串

sb.appendformat("<table style = 'font-size:12px' border='0' cellpadding='0' cellspacing='0' width='100%'> /n " +

"<tr>/n" +

"<td width='25%' align='left'>{0}</td>/n" +

"<td width='61%' align='right'>{1}</td>/n" +

"<td width='14%' align='right'><input type='text' name='t1' size='4' style='border-bottom:solid 1pt gray;border-top :solid 1pt gray; border-left:solid 1pt gray;border-right:solid 1pt gray;'> /n <input type='button' name='b1' size='6' value=go style='border-bottom:solid 1pt gray;border-top :solid 1pt gray; border-left:solid 1pt gray;border-right:solid 1pt gray;' onclick='go(t1,{2})'></td>/n" +

"</tr>/n" +

"</table>",leftinfo,

centerinfo.tostring(),

this.pages);



writer.write(sb.tostring());

}



protected override void onprerender(eventargs e)

{

base.onprerender (e);

if(!page.isclientscriptblockregistered("werew-332dfaf-fdafdsfdsafd"))

{

page.registerclientscriptblock("werew-332dfaf-fdafdsfdsafd",scriptstring);

}

}



}

}

最大的網(wǎng)站源碼資源下載站,

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湖州市| 临泉县| 堆龙德庆县| 治县。| 文水县| 璧山县| 浙江省| 广宁县| 惠来县| 开平市| 淄博市| 肇源县| 巴塘县| 遂溪县| 平安县| 水城县| 尉氏县| 昌吉市| 阳泉市| 梅州市| 正安县| 南部县| 丹阳市| 东安县| 元谋县| 延安市| 阿鲁科尔沁旗| 邯郸县| 盘山县| 泊头市| 昌吉市| 格尔木市| 黄龙县| 肥西县| 沙雅县| 宝鸡市| 专栏| 保德县| 东台市| 阜宁县| 乌兰县|