62,046
社区成员
发帖
与我相关
我的任务
分享
public class t3 : System.Web.UI.Page
{
private string str;//字符
private int strl;//字符总长度
private int pagesize;//每页显示的字符数
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
str="1234567891234567898522555";
pagesize=3;
strl=str.Length;
Response.Write(strl);
substr();
}
private void substr()
{
int ct=Int32.Parse(Request.QueryString["page"]);
if(strl==(strl/pagesize)*pagesize)//看看页面的总记录是否能被每页的记录数整除
{
for(int i=1;i<=strl/pagesize;i++)
{
Response.Write("页:"+(i)+"");
}
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++)
{
Response.Write("页:"+(i)+"");
}
string s=str.Substring((ct-1)*pagesize,strl-(ct-1)*pagesize);
Response.Write(s);
}
else //在不被整除的情况下其他页面的显示设置
{
for(int i=1;i<=strl/pagesize+1;i++)
{
Response.Write("页:"+(i)+"");
}
string s=str.Substring(pagesize*ct-pagesize,pagesize);
Response.Write(s);
}
}
}
newsID = Request.QueryString["NewID"]; //文章ID
int page = 1;
if (Request.QueryString["page"] != null)
{
page = int.Parse(Request.QueryString["page"].ToString());
}
string content = myNewRow["Article"].ToString();
ArrayList arrList = new ArrayList();
string pageString = "News.aspx?NewsID="+newsID+"&page="+page; //分页跳转
if (content.IndexOf("<p>[nextpage]</p>") > 1) //分页符<p>[nextpage]</p>
{
String[] tempList = content.Split(new String[] { "<p>[nextpage]</p>" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tempList.Length; i++)
{
arrList.Add(tempList[i]);
}
}
else
{
arrList.Add(content);
}
if (page < 1 || page > arrList.Count)
{
page = 1;
}
if (arrList.Count == 1)
{
newArticle.Text = (string)arrList[0];
Separate.Text = "";
}
else
{
if (page <= arrList.Count)
{
newArticle.Text = (string)arrList[page - 1];
}
else
{
newArticle.Text = (string)arrList[0];
}
Separate.Text = pageList.PageInfo(arrList.Count, 1, page, pageString);
}
public class PageList
{
#region 文章分页
/// <summary>
/// 文章分页
/// </summary>
/// <param name="count">新闻总页数</param>
/// <param name="pageList">每页显示几条新闻</param>
/// <param name="nowPage">当前是第几页</param>
/// <param name="pageStr">跳转页面</param>
/// <returns></returns>
public string PageInfo(int count, int pageList, int nowPage, string pageStr)
{
int pageCount = 1;
//string temp = "<font color='red'>共有" + count + "条新闻 </font>";
string temp = "";
if (count > 0)
{
string firstPage = "";//首页
string lastPage = "";//上一页
string nextPage = "";//下一页
string endPage = "";//未页
pageCount = count / pageList;
string selectStr = "跳转:<select name='PageSelect' onchange='window.location.href=value' id='newPageSelect'>";//下拉单
if ((count % pageList) > 0)
{
pageCount++;
}
for (int i = 1; i <= pageCount; i++)
{
if (i == nowPage)
{
selectStr += "<option selected='selected' value='" + pageStr + "page=" + i + "'>" + i + "</option>";
}
else
{
selectStr += "<option value='" + pageStr + "page=" + i + "'>" + i + "</option>";
}
}
selectStr += "</select>";
if (pageCount == 1)
{
firstPage = "<font color='#cccccc'>首页</font>";
lastPage = "<font color='#cccccc'>上页</font>";
nextPage = "<font color='#cccccc'>下页</font>";
endPage = "<font color='#cccccc'>尾页</font>";
}
else
{
if (nowPage == 1)
{
firstPage = "<font color='#cccccc'>首页</font>";
lastPage = "<font color='#cccccc'>上页</font>";
nextPage = "<a class='rlk' href='" + pageStr + "page=" + (nowPage + 1) + "'>下页</a>";
endPage = "<a class='rlk' href='" + pageStr + "page=" + pageCount + "'>尾页</a>";
}
else if (nowPage == pageCount)
{
firstPage = "<a class='rlk' href='" + pageStr + "page=1'>首页</a>";
lastPage = "<a class='rlk' href='" + pageStr + "page=" + (pageCount - 1) + "'>上页</a>";
nextPage = "<font color='#cccccc'>下页</font>";
endPage = "<font color='#cccccc'>尾页</font>";
}
else
{
nextPage = "<a class='rlk' href='" + pageStr + "page=" + (nowPage + 1) + "'>下页</a>";
lastPage = "<a class='rlk' href='" + pageStr + "page=" + (nowPage - 1) + "'>上页</a>";
firstPage = "<a class='rlk' href='" + pageStr + "page=1'>首页</a>";
endPage = "<a class='rlk' href='" + pageStr + "page=" + pageCount + "'>尾页</a>";
}
}
temp += " " + firstPage + " " + lastPage + " " + nextPage + " " + endPage + " " + selectStr;
}
else
{
temp = "";
}
return temp;
}
#endregion
}