天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

asp.net 文章內(nèi)容分頁顯示的代碼

ASPx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ArticlePage.ASPx.cs" Inherits="ArticlePage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>文章分頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="text-align: center;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" style="width: 400px; background-color: #ffff99;">
<table style="width: 100%">
<tr>
<td style="width: 100%; border-top: #ff3300 2px dotted; border-left-width: 2px; border-left-color: #ff3300; border-bottom: #ff3300 2px dotted; border-right-width: 2px; border-right-color: #ff3300; height: 25px; text-align: center;">
<%=ArticleTitle %></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width: 400px; height: 100%;" align="left">
<p style="background-color: oldlace">
<%=Article %>
</p>
</td>
</tr>
<tr>
<td style="width: 400px; background-color: #ffff99; height: 48px;">
<table style="width: 100%">
<tr>
<td style="width: 100%; border-top: #ff3300 2px dotted; border-left-width: 2px; border-left-color: #ff3300; border-bottom: #ff3300 2px dotted; border-right-width: 2px; border-right-color: #ff3300;" align="left">
<p>
<ASP:HyperLink ID="firstLink" runat="server" Visible="False">首頁</ASP:HyperLink>
<ASP:HyperLink ID="preLink" runat="server" Visible="False"></ASP:HyperLink>
<ASP:HyperLink ID="nextLink" runat="server" Visible="False"></ASP:HyperLink>
<ASP:HyperLink ID="lastLink" runat="server" Visible="False">末頁</ASP:HyperLink>
</p>
<p>
<%
if(pageSum>1)
{
for (int i = 1; i <= pageSum; i++)
{
if (pageNo == i)
{
%>
<%=i%>
<%
}
else
{
%>
<a href="?page=<%=i %>"><%=i%></a>
<%
}
}
}
%>
頁數(shù):<%=pageNo %>/<%=pageSum %>
</p></td>
</tr>
</table>
</td>
</tr>
</table>
<br />
</div>
</form>
</body>
</html>
//==========================
ASPx.cs:
(C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ArticlePage : System.Web.UI.Page
{
protected string Article = "", ArticleTitle="";
protected int pageNo = 1, pageSum = 1;
protected void Page_Load(object sender, EventArgs e)
{
//實(shí)際應(yīng)用中,此處的數(shù)據(jù)通過操作數(shù)據(jù)庫來獲取
ArticleTitle = "文章標(biāo)題";
string filename = "20091795819.html";
string mPath = Server.MapPath("h3g/");
string filepath = mPath + filename;
ShowArticle(filepath);
}
protected void ShowArticle(string filepath)
{
string page = Request.Params["page"];
int perPageLine = 5;//每頁行數(shù)
ArrayList al = fileOpr.ReadFileContentToArrayList(filepath);//按行讀取文件內(nèi)空到數(shù)組中
int contentLine = al.Count;
pageSum = (int)System.Math.Ceiling((double)contentLine / perPageLine);//總頁數(shù),進(jìn)1取整
if (page == null || page == "" || page == "1")
{
pageNo = 1;
if (contentLine <= perPageLine)
{
for (int i = 0; i < contentLine; i++)
{
Article += al[i].ToString();
}
}
else
{
for (int i = 0; i < perPageLine; i++)
{
Article += al[i].ToString();
}
firstLink.Visible = false;
preLink.Visible = false;
nextLink.NavigateUrl = "?page=" + (pageNo + 1);
nextLink.Visible = true;
lastLink.NavigateUrl = "?page=" + pageSum;
lastLink.Visible = true;
}
}
else
{
pageNo = int.Parse(page);
if (pageNo < pageSum)
{
for (int i = perPageLine * (pageNo - 1); i < perPageLine * pageNo; i++)
{
Article += al[i].ToString();
}
firstLink.NavigateUrl = "?page=1";
firstLink.Visible = true;
preLink.NavigateUrl = "?page=" + (pageNo - 1);
preLink.Visible = true;
nextLink.NavigateUrl = "?page=" + (pageNo + 1);
nextLink.Visible = true;
lastLink.NavigateUrl = "?page=" + pageSum;
lastLink.Visible = true;
}
else
{
for (int i = contentLine - perPageLine * (pageSum - 1); i < contentLine; i++)
{
Article += al[i].ToString();
}
firstLink.NavigateUrl = "?page=1";
firstLink.Visible = true;
preLink.NavigateUrl = "?page=" + (pageNo - 1);
preLink.Visible = true;
nextLink.Visible = false;
lastLink.Visible = false;
}
}
}
}
重用類fileOpr.cs:
fileOpr.ReadFileContentToArrayList(filepath);中的方法:
public static ArrayList ReadFileContentToArrayList(string filepath)
{
ArrayList al = new ArrayList();
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
StreamReader srd = new StreamReader(fs, Encoding.Default);
//使用StreamReader類來讀取文件
srd.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = srd.ReadLine();
while (strLine != null)
{
strLine = srd.ReadLine();
al.Add(strLine + "/n");
}
//關(guān)閉此StreamReader對象
srd.Close();
fs.Dispose();
fs.Close();
return al;
}
注:有種文章分頁的思路是用截取文本字符數(shù)的方法來處理,這個(gè)方法當(dāng)文章內(nèi)容是html代碼的話,分頁后會(huì)引起排版問題。
上面代碼的方法思路是按行數(shù)來處理,這個(gè)方法個(gè)人認(rèn)為相對更好些。在后臺(tái)管理文章內(nèi)容文件時(shí),保證html代碼的良好排版換行即可。

AspNet技術(shù)asp.net 文章內(nèi)容分頁顯示的代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 4k岛国精品午夜高清在线观看 | 白人大战34厘米黑人BD | 六月婷婷国产精品综合 | 宿舍BL 纯肉各种PLAY H | 日本69xx 老师 | 久 久 亚洲 少 妇 无 码 | 久久机热视频免费 | 国产成人免费观看在线视频 | 亚洲AV噜噜狠狠网址蜜桃尤物 | 久久国产精品麻豆AV影视 | 成人亚洲乱码在线 | 日韩欧美一区二区三区免费看 | 美女搜查官被高难度黑人在线播放 | 女人18毛片 | 99热在线视频这里只精品 | 亚洲伊人久久网 | 国产精品18久久久久久欧美网址 | 成人影院午夜久久影院 | 亚洲婷婷天堂综合国产剧情 | 久cao在线香蕉 | 久久视频在线视频观看精品15 | 日韩高清在线亚洲专区 | 97影院午夜午夜伦不卡 | 亚洲AV永久无码精品老司机蜜桃 | 久久精品视在线观看2 | 人妻免费久久久久久久了 | 亚欧免费观看在线观看更新 | 国产精品视频成人 | 久久中文字幕人妻熟AV女蜜柚M | 暖暖日本大全免费观看 | yellow在线观看免费观看大全 | 欧美日本高清动作片www网站 | 视频成人app永久在线观看 | 亚洲欧美日韩中字视频三区 | 翁公与小莹在客厅激情 | 亚洲人成电影网站色2017 | 国产亚洲视频在线播放香蕉 | ebc5恐怖5a26房间 | 日本无码人妻精品一区二区视频 | 国模啪啪久久久久久久 | 久久精品热在线观看85 |