加入一篇几万字的文章,想让他自动分页,Pagesize自己制定我的文章内容比如是:asoidhsadhasjkdhasjkdas
d
asd
asasdasdasdas
d
asd
sadopgjdfgjdklfgsdasdasda
dfsghasdsadsadasdasda
fhkgfhjklghsdasdasdas
gfh
gf
hfgdasdasdas
hg
fhgfklhkfldasdasdasdasdas
....
我想让他这样
asoidhsadhasjkdhasjkdas
d
asd
asasdasdasdas
d
asd
sadopgjdfgjdklfgsdasdasda
dfsghasdsadsadasdasda
[1] [2] [...]第二页是
fhkgfhjklghsdasdasdas
gfh
gf
hfgdasdasdas
hg
fhgfklhkfldasdasdasdasdas
....第[..]页是
....
怎么做到呢?刚刚看了好多材料,不是很明白
请大哥们说说自己的做法吧,小弟这里谢过了^o^
d
asd
asasdasdasdas
d
asd
sadopgjdfgjdklfgsdasdasda
dfsghasdsadsadasdasda
fhkgfhjklghsdasdasdas
gfh
gf
hfgdasdasdas
hg
fhgfklhkfldasdasdasdasdas
....
我想让他这样
asoidhsadhasjkdhasjkdas
d
asd
asasdasdasdas
d
asd
sadopgjdfgjdklfgsdasdasda
dfsghasdsadsadasdasda
[1] [2] [...]第二页是
fhkgfhjklghsdasdasdas
gfh
gf
hfgdasdasdas
hg
fhgfklhkfldasdasdasdasdas
....第[..]页是
....
怎么做到呢?刚刚看了好多材料,不是很明白
请大哥们说说自己的做法吧,小弟这里谢过了^o^
只能通过加入分页码来进行分页吧,如需要分页的时候,插入一特别的字符串<Pager>!
给个例子你把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;
using System.Data.SqlClient;
using System.IO;
using System.Text;
public partial class BlogListDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int id = int.Parse(Request.QueryString["id"].ToString());
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MovieConnectionString"].ToString()); SqlCommand cmd = new SqlCommand();
SqlParameter Sqlid = new SqlParameter("@id", SqlDbType.Int);
Sqlid.Value = id;
cmd.Parameters.Add(Sqlid);
cmd.CommandText = "select BTopic from BlogList where BID=@id";
cmd.Connection = con;
con.Open();
string topic = cmd.ExecuteScalar().ToString();
con.Close();
this.Label1.Text = topic;
string path = "E:\\News\\" + topic + ".txt";
FileStream fs = new FileStream(path, FileMode.Open);
StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312"));
string content = sr.ReadToEnd();
sr.Dispose();
fs.Dispose();
string[] contentArray = StringSplit(content, "<#####>");
int PageCount = contentArray.Length;
this.lbTotal.Text = "共<b><font color='#FF0000'>" + PageCount.ToString() + "</font></b>页";
int CurPage;
if (System.Web.HttpContext.Current.Request.Params["Page"] != null)
{
CurPage = Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]);
if (CurPage == 1)
{
this.hplPrv.Enabled = false;
}
}
else
{
CurPage = 1;
this.hplPrv.Enabled = false;
} if (CurPage < 1) CurPage = 1;
if (Convert.ToInt32(System.Web.HttpContext.Current.Request.Params["Page"]) >= PageCount)
{
CurPage = PageCount;
this.hpyNext.Enabled = false;
}
TableRow tr = new TableRow();
for (int i = 0; i < PageCount; i++)
{
TableCell tc = new TableCell(); if (i == CurPage - 1)
tc.Controls.Add(new LiteralControl("<span style='color:red;font-weight:bold'>" + (i + 1).ToString() + "</span>"));
else
{
HyperLink hplNum = new HyperLink();
hplNum.Text = (i + 1).ToString();
hplNum.Font.Underline = false;
hplNum.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(i + 1) + "&id=" + Request.QueryString["id"].ToString();
tc.Controls.Add(hplNum); }
tr.Cells.Add(tc);
}
this.Table1.Rows.Add(tr); this.lbCurrent.Text = "第<b><font color='#FF0000'>" + CurPage.ToString() + "</font></b>页";
this.hplPrv.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&id=" + Request.QueryString["id"].ToString();
this.hpyNext.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&id=" + Request.QueryString["id"].ToString();
this.lbContent.Text = "<img src='Images/NewsDetails.jpg' style='float:left'/>" + "<br/> " + contentArray[CurPage - 1].ToString(); }
}
protected string[] StringSplit(string strsource, string strSplit)
{
string[] strtmp=new string[1];
int index = strsource.IndexOf(strSplit, 0);
if (index < 0)
{
strtmp[0] = strsource;
return strtmp;
}
else
{
strtmp[0] = strsource.Substring(0, index);
return StringSplit(strsource.Substring(index + strSplit.Length), strSplit, strtmp);
}
}
private string[] StringSplit(string strSource, string strSplit, string[] attachArray)
{
string[] strtmp = new string[attachArray.Length + 1];
attachArray.CopyTo(strtmp, 0); int index = strSource.IndexOf(strSplit, 0);
if (index < 0)
{
strtmp[attachArray.Length] = strSource;
return strtmp;
}
else
{
strtmp[attachArray.Length] = strSource.Substring(0, index);
return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
}
}
}
<div style="width: 1024px; left: 0px; position: relative; top: 0px;" align="left">
<div style="width: 1024px; height: 100px" align="center">
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="24px" ForeColor="Red"
Height="18px" Width="478px"></asp:Label><br />
<br />
发表于:<asp:Label ID="Label2" runat="server" Width="140px"></asp:Label><br />
<hr width=1024px />
</div>
<div align="center" style="width: 698px; height: 420px; position: static;">
<asp:Label ID="lbContent" runat="server" Font-Bold="False" ForeColor="Red" Width="100%" Font-Size="14px"></asp:Label></div>
<br />
<br />
<br />
<br />
<div align="center" style="width: 704px; height: 25px; position: static;">
<div style="text-align: center">
<table>
<tr>
<td >
<asp:Label ID="lbTotal" runat="server"></asp:Label></td>
<td >
<asp:Label ID="lbCurrent" runat="server"></asp:Label></td>
<td>
<asp:HyperLink ID="hplPrv" runat="server">上一页</asp:HyperLink></td>
<td >
<asp:Table ID="Table1" runat="server">
</asp:Table>
</td>
<td >
<asp:HyperLink ID="hpyNext" runat="server">下一页</asp:HyperLink></td>
</tr>
</table>
</div>
</div>
安装一下,分页的效果可以达到跟Google的分页式的,
什么都有,
好像是在PetShop里吧,记得不太清楚了~
/// <summary>
/// 取出内容
/// </summary>
/// <returns></returns>
public string content()
{
string title = "<div align='center'>";
pagesize=1000;
try
{
//替换掉空格
str = ds.Tables[0].Rows[0]["news_content"].ToString().Replace("?"," ");
strl = str.Length;
int ct = 1;
string b = Request.QueryString["page"];
if (b != null)
{
ct = Int32.Parse(Request.QueryString["page"]);
}
if(strl==(strl/pagesize)*pagesize)//看看页面的总记录是否能被每页的记录数整除
{
for(int i=1;i<=strl/pagesize;i++)
{
title += "<a href=CattleLook.aspx?titleid=" + getNum() + "&page="+i +">"+(i)+"</"+"a>页 ";
}
string s=str.Substring(pagesize*ct-pagesize,pagesize);
Response.Write(s);
}
else if(ct*pagesize>strl)//在不被整除的情况下,最后一页的设置,如字符长13,每页3,则处理最后那一页的显示
{
for(int i=1;i<=(strl/pagesize)+1;i++)
{
title += "<a href=CattleLook.aspx?titleid=" + getNum() + "&page=" + i + ">" + (i) + "</" + "a>页 ";
}
string s=str.Substring((ct-1)*pagesize,strl-(ct-1)*pagesize);
Response.Write(s);
}
else //在不被整除的情况下其他页面的显示设置
{
for(int i=1;i<=strl/pagesize+1;i++)
{
title += "<a href=CattleLook.aspx?titleid=" + getNum() + "&page=" + i + ">" + (i) + "</" + "a>页 ";
}
string s=str.Substring(pagesize*ct-pagesize,pagesize);
Response.Write(s);
}
title += "</div>";
}
catch{}
return title;
}
或者类似于数据库分页 其实分隔字符也不是必须的