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

首頁 > 編程 > .NET > 正文

用Asp.net實現新聞分頁

2024-07-10 12:57:33
字體:
來源:轉載
供稿:網友
思想:方法是在后臺添加新聞時,估計在應該分頁的地方插入一個標記(我插入的是[page]),在前臺顯示時,我傳入了一個參數page,表示要顯示第幾頁,在顯示頁面,我根據標記[page]分別把新聞內容放入數組中,如果傳入的參數page的值是1,我就取arr[0]的值,如果是第二個......
還有,我把分頁的html代碼是根據統計的[page]來決定是否顯示的

baseinfo是我定義的基本信息類:

public class baseinfo
?{
??public string id,summary,content,picture;
??public datetime publictime;

??public stringbuilder pagefoot = new stringbuilder();

??public baseinfo()
??{?
???
??}

??//添加
??public int add()
??{
???...??
??}

??//更新
??public int update()
??{
???...
??}
??
??//初始化
??public void init()
??{
???...
??}
?}


在這個頁面要傳入兩個參數page和id,第一次鏈接到這個頁面傳入的page值應該是1,而且一定是1,id是

新聞的id,如新聞id=1的連接應該是baseinfodetail.aspx?page=1&id=1
nextat是后一個[page]的位置,backat是前一個[page]標志的位置,pagefoot是一個html表格我加了

runat=server
代碼如下:
baseinfodetail.aspx的部分代碼如下:
baseinfo info = new baseinfo();??
????info.id = request.querystring["id"];?
????info.init();

????

//******************************************************************************************

**********
????//分頁
????// i:計算標志“[page]”的個數的
????//
????//???????????????? --? 夢凡? 2004年8月14號19:32
????int nextat = -4,i=0,backat = 0;
????string[] tempcontent = new string[20] ;
????do
????{
?????nextat += 4;
?????nextat = info.content.indexof("[page]",nextat);??

????????????

?
?????if(nextat != -1)
?????{
??????i++;
??????tempcontent[i] = info.content.substring

(backat,math.abs(nextat-backat));
??????backat = nextat + 6;
?????}
????}while(nextat != -1);
??????
????int currentpage = convert.toint32(request.querystring

["page"]);
????if(i>0)
????{
?????info.content = tempcontent[currentpage];
?????this.pagefoot.visible = true;
????}
????else
?????this.pagefoot.visible = false;
?????
????info.pagefoot.append("共" +i.tostring()+"頁 ");
????for(int j=1;j<=i;j++)
????{
?????info.pagefoot.append("[

href='baseinfodetail.aspx?page=" +j.tostring()+ "&id=" +info.id+ "'>" +j.tostring()+ "]

");
????}
????if(currentpage != i)
????{
?????currentpage += 1;
?????info.pagefoot.append("下一頁 ");
????}
????
????

//******************************************************************************************

**********



  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 南召县| 恩施市| 鹤峰县| 平江县| 石城县| 阿荣旗| 宣武区| 巴楚县| 哈密市| 镇坪县| 于田县| 渑池县| 紫阳县| 崇明县| 曲靖市| 全南县| 集安市| 岑溪市| 乌兰浩特市| 六安市| 苏尼特左旗| 玛沁县| 平谷区| 麦盖提县| 芦溪县| 吴堡县| 叙永县| 马龙县| 离岛区| 紫金县| 安龙县| 澄江县| 普兰店市| 牙克石市| 巴彦淖尔市| 四会市| 江都市| 新密市| 缙云县| 普陀区| 碌曲县|