国产探花免费观看_亚洲丰满少妇自慰呻吟_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技術!
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 通许县| 镇江市| 奉新县| 马公市| 双柏县| 西林县| 西乌珠穆沁旗| 蕉岭县| 连南| 阿拉尔市| 绥滨县| 当涂县| 胶州市| 潮州市| 湖北省| 广德县| 威海市| 青海省| 庄浪县| 石屏县| 苏尼特右旗| 太仆寺旗| 西宁市| 长治市| 浦北县| 和龙市| 丰顺县| 灯塔市| 芦溪县| 当阳市| 历史| 固安县| 南陵县| 太谷县| 大化| 舞阳县| 乃东县| 和硕县| 全南县| 政和县| 甘洛县|