All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用ASP.NET代码实现备份SQL,Server数据库_[Asp.Net教程]
Javscript实现表单复选框的全选功能_JavaScript技术_编程技术
LINQ,的演变及其对,C#,设计的影响_.net资料_编程技术
动态网页技术PHP通过参数来生成MYSQL语句类_php资料_编程技术
最具web2.0意义的豆瓣网站的几点价值_JavaScript技术_编程技术
C#中PerformanceCounter组件应用实例
事半功倍之javascript(4)_JavaScript技术_编程技术
visual c++添加菜单命令处理函数
专家讲解用.NET编写串口程序的一点心得_.net资料_编程技术
巧妙利用XSLT将XML数据转换成HTML_[XML教程]
Reading number is top 10 pictures
乳娘帕梅拉安德森1
福利是必须的
各种囧况!玩游戏最不喜欢出现的十件事
毕姥爷事件,告诉你6条真理
BingBingFan apple dew point photo gallery5
Entered the goddess in the AD1
The money of more than 100 countries and regions21
No trading, no killing
NeedWallpaper13
Beautiful Japanese beauty(漂亮的日本美女)2
Download software ranking
Unix video tutorial5
美女写真2
传奇私服架设教程-chm
C#编程思想
网页特效实例大全
Popkart Cracked versions Mobile phone games
Sora aoi, the nurse, uniform ,nursing assistant
SQL2000 For 4IN1
Unix video tutorial19
Love the forty days
delv published in(发表于) 2014/1/27 6:51:36 Edit(编辑)
文章,记录按内容分页显示,根据文章内容按字数进行分页_[Asp.Net教程]

文章,记录按内容分页显示,根据文章内容按字数进行分页_[Asp.Net教程]

文章,记录按内容分页显示,根据文章内容按字数进行分页_[Asp.Net教程]

在很多时候我们对一些文章很长时,往往浏览时用鼠标滑来滑去非常麻烦。要是我们对这篇文章划分为几个
页面,用不同的面页去浏览不但看起来很爽,而且效率方面也是大的提高了。

下面是一段代码,给大家做个参考:
先从数据库中检索出要文章,(很长的文章)

private string OutputArticle()
{//Only output one Record of the "AriticID" is 2
string m_strRet = "";
。。。。
//检索数据库文章的代码。
return m_strRet;
}

对文章进行分页:
public string OutputBySize(string p_strContent)
{
int m_intPageSize=1000;//文章每页大小
int m_intCurrentPage = 1;//设置第一页为初始页
int m_intTotalPage = 0;
int m_intArticlelength=p_strContent.Length;//文章长度
if (m_intPageSize < m_intArticlelength)
{//如果每页大小大于文章长度时就不用分页了
if (m_intArticlelength % m_intPageSize == 0)
{//set total pages count
m_intTotalPage = m_intArticlelength / m_intPageSize;
}
else
{//if the totalsize
m_intTotalPage = m_intArticlelength / m_intPageSize + 1;
}
if (Request.QueryString["pages"] != null)
{//set Current page number
try
{//处理不正常的地址栏的值
m_intCurrentPage = Convert.ToInt32(Request.QueryString["pages"]);
if (m_intCurrentPage > m_intTotalPage)
m_intCurrentPage = m_intTotalPage;
}
catch
{
m_intCurrentPage = m_intCurrentPage;
}
}
//set the page content 设置获取当前页的大小
m_intPageSize = m_intCurrentPage < m_intTotalPage ? m_intPageSize : (m_intArticlelength - m_intPageSize * (m_intCurrentPage - 1));
string m_strRet = p_strContent.Substring(m_intPageSize * (m_intCurrentPage - 1), m_intPageSize);
string m_strPageInfo = "

";
for (int i = 1; i <= m_intTotalPage; i++)
{
if (i == m_intCurrentPage)
m_strPageInfo += "" + i + "|";
else
m_strPageInfo += "" + i + "|";
}
//输出显示各个页码
this.labPageNumber.Text = m_strPageInfo;
}
return m_strRet;
}

最后在页面加载事件中调用上面的方法:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string m_strContent = OutputArticle();
this.labContent.Text = OutputBySize(m_strContent);
}
}
页面代码很简单为:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewArticle.aspx.cs" Inherits="ViewArticle" %>





Untitled Page
















一个简单的按内容分页就是这样了。简单吧。

来源:seebook的blog






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.