分页|解决|数据|数据库using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI.WebControls;
namespace OSLeagueForumXP.admin
{
/// <summary>
/// 编辑公告页面
/// </summary>
public class EditBoardPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink hlkPrev;
protected System.Web.UI.WebControls.HyperLink hlkNext;
protected System.Web.UI.WebControls.HyperLink hlkFirst;
protected System.Web.UI.WebControls.HyperLink hlkEnd;
protected System.Web.UI.WebControls.Label lblPage;
protected System.Web.UI.WebControls.Panel pelMain;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.HyperLink hlkReturn;
protected System.Web.UI.WebControls.Panel pelMessage;
protected System.Web.UI.WebControls.DataList DLBoard;
private void Page_Load(object sender, System.EventArgs e)
{
Process clsProcess = new Process();
clsProcess.Common();
const int PAGESIZE = 5;
int intPageCount;
int intPage;
if(Request.QueryString["Page"] == null)
{
intPage = 1;
}
else
{
intPage = Int32.Parse(Request.QueryString["Page"]);
}
int intStart = (intPage - 1) * PAGESIZE;
SqlDataReader SqlReader = clsProcess.GetBoardCount();
if(SqlReader.Read())
{
intPageCount = (int)SqlReader["PageCount"];
}
else
{
intPageCount = 0;
}
int intAllPage = (int) Math.Floor(intPageCount / PAGESIZE) + 1;
DLBoard.DataSource = clsProcess.GetBoard(intStart,PAGESIZE);
DLBoard.DataBind();
if(clsProcess.GetBoard(intStart,PAGESIZE).Count == 0)
{
lblMessage.Text = "出现错误:<font color=\"red\">没有公告,请先添加公告</font>";
hlkReturn.Text = "添加公告";
pelMain.Visible = false;
pelMessage.Visible = true;
}
else
{
lblPage.Text = intAllPage.ToString() + "/" + intPage.ToString();
if(intAllPage == 1)
{
hlkFirst.NavigateUrl = "";
hlkPrev.NavigateUrl = "";
hlkNext.NavigateUrl = "";
hlkEnd.NavigateUrl = "";
}
else if(intPage == 1)
{
hlkFirst.NavigateUrl = "";
hlkPrev.NavigateUrl = "";
hlkNext.NavigateUrl = "editboard.aspx?Page=" + (intPage + 1);
hlkEnd.NavigateUrl = "editboard.aspx?Page=" + intAllPage;
}
else if(intPage == intAllPage)
{
hlkFirst.NavigateUrl = "editboard.aspx?Page=1";
hlkPrev.NavigateUrl = "editboard.aspx?Page=" + (intPage - 1);
hlkNext.NavigateUrl = "";
hlkEnd.NavigateUrl = "";
}
else
{
hlkFirst.NavigateUrl = "editboard.aspx?Page=1";
hlkPrev.NavigateUrl = "editboard.aspx?Page=" + (intPage - 1);
hlkNext.NavigateUrl = "editboard.aspx?Page=" + (intPage + 1);
hlkEnd.NavigateUrl = "editboard.aspx?Page=" + intAllPage;
}
}
}
#region Web Form Designer generated code
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
}
}
解决分页的例子。使用DataSet绑定到DataList实现的。数据库使用
80酷酷网 80kuku.com