asp.net新闻页面分页
2008-03-28 11:02
507 查看
如果一篇文章比较长,我们在一页面显示出来太长,不好看,想进行分页面。这在asp.net中如何处理呢。在网上查了一下资料,发现都是要在新闻添加 时加一下标记,但没有具体做法,后来有一个兄弟提出可以根据字数进行分。而且可以根据<P>这个标记来分。我就根据这个想法。写了下面的程 序,如果你有更好的方法,可以告诉我。给我留言。
因为一般情况下我们在发布新闻的时候,都是采用在线编辑器来处理,在线编辑器里断行都是大写的<P>下面是我的代码,没有美化。
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
int page = Convert.ToInt32(Request.QueryString["page"].ToString());
string strsql = "select top 1 * from pageContent where title='chen1'";
string[] strContent = null;
SqlDataReader dr = cdb.mydr(strsql);
if(dr.Read())
{
strContent = filesplit(dr["contents"].ToString());
}
dr.Close();
if(strContent[page-1]!=null)
{
Response.Write(strContent[page-1]);
}
else
{
Response.Write("为什么是空呢");
}
for(int i=0;i<strContent.Length;i++)
{
if(strContent[i]!=null)
{
int npage = i+1;
Response.Write("<a href=addView.aspx?page=" + npage + ">" + npage + "</a>");
}
}
}
}
public string[] filesplit(string contents)
{
int fileindex = 0;
string[] splitfile = new string[10];
while(contents.Length>10 && fileindex<9)
{
if(contents.IndexOf("<P>",10)<0) break;
splitfile[fileindex] = contents.Substring(0,contents.IndexOf("<P>",10));//这里注意这里的10是字数,我是为了测试而采用10,你可以根据你的新闻页面再设置,我想最少也得200字吧。呵呵。。。。。。
contents = contents.Remove(0,splitfile[fileindex].Length);
fileindex++;
}
splitfile[fileindex] = contents;
return splitfile;
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
因为一般情况下我们在发布新闻的时候,都是采用在线编辑器来处理,在线编辑器里断行都是大写的<P>下面是我的代码,没有美化。
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
int page = Convert.ToInt32(Request.QueryString["page"].ToString());
string strsql = "select top 1 * from pageContent where title='chen1'";
string[] strContent = null;
SqlDataReader dr = cdb.mydr(strsql);
if(dr.Read())
{
strContent = filesplit(dr["contents"].ToString());
}
dr.Close();
if(strContent[page-1]!=null)
{
Response.Write(strContent[page-1]);
}
else
{
Response.Write("为什么是空呢");
}
for(int i=0;i<strContent.Length;i++)
{
if(strContent[i]!=null)
{
int npage = i+1;
Response.Write("<a href=addView.aspx?page=" + npage + ">" + npage + "</a>");
}
}
}
}
public string[] filesplit(string contents)
{
int fileindex = 0;
string[] splitfile = new string[10];
while(contents.Length>10 && fileindex<9)
{
if(contents.IndexOf("<P>",10)<0) break;
splitfile[fileindex] = contents.Substring(0,contents.IndexOf("<P>",10));//这里注意这里的10是字数,我是为了测试而采用10,你可以根据你的新闻页面再设置,我想最少也得200字吧。呵呵。。。。。。
contents = contents.Remove(0,splitfile[fileindex].Length);
fileindex++;
}
splitfile[fileindex] = contents;
return splitfile;
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
相关文章推荐
- asp.net调用远程Web Service的二种方法
- asp.net页面之间传中文是乱码的处理方法
- ASP sql中查询的类型及符号的注意事项
- asp.net对XML的增删改查
- 关于asp.net无刷新联动的一点补充说明
- asp.net无刷新三级联动
- FSO 遍历文件夹,按时间排序,可以删除
- ASP.NET 安全认证(转自:寒羽枫cityhunter172)
- ASP.NET 2.0 中收集的小功能点
- 中文VS2008中安装ASP.NET MVC框架出现问题的解决方法
- ASP.NET程序中常用编程代码(2)
- ASP.NET程序中常用编程代码(1)
- ASP字符串函数大全
- ASP页面sql查询超时问题?
- ASP数据库语法总结
- 每个ASP程序员必备的知识
- 用VB编写ActiveX DLL实现ASP编程
- ASP六大对象介绍
- SQL注入天书-ASP注入漏洞全接触
- ASP在服务器自动解压RAR文件