Paging long articles in ASP.NET using C#
Paging long articles in ASP.NET using C#
Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that gets posted to a database.
The Regular Expression Split() method returns a one-dimensional zero-based array containing a number of substrings, so it is perfect for this job. What I want to do is take an article (which is a string) and divide it into substrings. In order to do this, I need a delimiter, and I use <!--pagebreak-->. As I enter the article into the database, I place <!--pagebreak--> at the points I want to break the article.
Then, having extracted the article from the database, I pass it to the following static method which I have in a utility class:
public static string PageArticle(string Article)
{
string Output;
string ThisPage = HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"];
string PageNo;
PageNo = HttpContext.Current.Request.QueryString["Page"];
if (Article.IndexOf("<!--pagebreak-->") != -1)
{
string[] Pages = Regex.Split(Article, "<!--pagebreak-->");
int TotalPages = Pages.GetUpperBound(0) + 1;
int Counter = 1;
int PageNumber = 1;
if (PageNo != null)
{
PageNumber = System.Convert.ToInt32(PageNo);
}
Output = Pages[PageNumber - 1];
Output += "<p>Go to Page ";
while (Counter <= TotalPages)
{
if (Counter == PageNumber)
{
Output += Counter.ToString() + " ";
}
else
{
Output += "<a href="\" mce_href="\""" + ThisPage + "?Page=" + Counter.ToString();
Output += "\">" + Counter.ToString() + "</a> ";
}
Counter++;
}
Output += "</p>";
}
else
{
Output = Article;
}
re
相关文档:
第一:
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); } 第二:
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.location.href=document.URL; < /script&g ......
在不支持Cookies的移动设备模拟器中无法正常进行表单验证,联想到昨天使用web.config设置cookieless属性时会在访问时会出现"Cannot use a leading .. to exit above the top directory"的异常,自然而然的我就想到了前一段时间困扰我很久的一个站点异常无法使用前导 .. 在顶级目录上退出(Cannot use a leading .. to exit abo ......
Internet 类
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
namespace DownData
{
class internet
{
&nb ......
http://www.cnblogs.com/chsword/archive/2008/03/10/dotnetmvcframework.html
以下文章属于ASP.NET MVC 1.0 正式版
ASP.NET MVC雕虫小技 1-2
ASP.NET MVC 重点教程一周年版 第十一回 母版页、用户自定义控件及文件上传
ASP.NET MVC 重点教程一周年版 第十回 请求Controller
ASP.NET MVC 重点教程一周年版 第九回 H ......
在Global.asax
需要回顾的知识点是 线程 和 文本文件的读写。
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
string logpath;
Thread thread;
......