首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于文章分页解决办法

2012-01-31 
关于文章分页加入一篇几万字的文章,想让他自动分页,Pagesize自己制定我的文章内容比如是:asoidhsadhasjkdh

关于文章分页
加入一篇几万字的文章,想让他自动分页,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^



[解决办法]
自己学个方法.至于怎么写,我还在进行中.写好了拿来一起研究研究!
[解决办法]

通过JS控制吧,写个函数输出,如果字节数到了 或超过多少有换行符时 就分一页,其他隐藏!
[解决办法]
好象很难实行精确的分页.
只能通过加入分页码来进行分页吧,如需要分页的时候,插入一特别的字符串<Pager>!
[解决办法]
文章的分页我的方法是加标签,就是在要分页的地方加上分页标签
给个例子你把[code=C#][/code]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/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + 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);
}
}
}
[code=HTML][/code]<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;">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<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>
&nbsp; &nbsp;
</div>
[解决办法]
长文章分页用首页下页上页未页足够了!没必要弄那么烦!最多再加一个跳转!可是文章分页用的着吗?
[解决办法]
按照字数或者行数把文章划分成几个大的片段,那就可以了。不过最好还是人手划分,否则导致上下文关联紧密的比分被自动划分开了,阅读起来就很不好。
[解决办法]
抢个位~
[解决办法]
.net里不是有一个分页的吗?
安装一下,分页的效果可以达到跟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("?","&nbsp;");
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>页&nbsp;";
}
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>页&nbsp;";
}
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>页&nbsp;";
}
string s=str.Substring(pagesize*ct-pagesize,pagesize);
Response.Write(s);
}
title += "</div>";
}
catch{}
return title;
}
[解决办法]
或者如楼上所说 插入分隔符 然后灵活组织字符串的Split/SubString/IndexOf和string.Join()函数实现
或者类似于数据库分页 其实分隔字符也不是必须的

热点排行