后台逻辑:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Wuqi.Webdiyer;
public partial class Default2 : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=localhost;database=AspNetPager;uid=sa;pwd=asen");
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
cmd = new SqlCommand("select count(newsid) from wqnews", conn);
conn.Open();
pager.RecordCount = (int)cmd.ExecuteScalar();
conn.Close();
BindData();
}
}
/// <summary>
/// 绑定数据集和显示记录信息
/// </summary>
public void BindData()
{
//绑定数据集
cmd = new SqlCommand("GetPagedNews", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@pageindex", pager.CurrentPageIndex);
cmd.Parameters.Add("@pagesize", pager.PageSize);
conn.Open();
dataGrid1.DataSource = cmd.ExecuteReader();
dataGrid1.DataBind();
conn.Close();
//显示记录信息
pager.CustomInfoText = "记录总数:<b>" + pager.RecordCount.ToString() + "</b>";
pager.CustomInfoText += " 总页数:<b>" + pager.PageCount.ToString() + "</b>";
pager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";
}
/// <summary>
/// 页面转换绑定的函数
/// </summary>
/// <param name="src"></param>
/// <param name="e"></param>
public void ChangePage(object src, PageChangedEventArgs e)
{
pager.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Wuqi.Webdiyer;
public partial class Default2 : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=localhost;database=AspNetPager;uid=sa;pwd=asen");
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
cmd = new SqlCommand("select count(newsid) from wqnews", conn);
conn.Open();
pager.RecordCount = (int)cmd.ExecuteScalar();
conn.Close();
BindData();
}
}
/// <summary>
/// 绑定数据集和显示记录信息
/// </summary>
public void BindData()
{
//绑定数据集
cmd = new SqlCommand("GetPagedNews", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@pageindex", pager.CurrentPageIndex);
cmd.Parameters.Add("@pagesize", pager.PageSize);
conn.Open();
dataGrid1.DataSource = cmd.ExecuteReader();
dataGrid1.DataBind();
conn.Close();
//显示记录信息
pager.CustomInfoText = "记录总数:<b>" + pager.RecordCount.ToString() + "</b>";
pager.CustomInfoText += " 总页数:<b>" + pager.PageCount.ToString() + "</b>";
pager.CustomInfoText += " 当前页:<font color=\"red\"><b>" + pager.CurrentPageIndex.ToString() + "</b></font>";
}
/// <summary>
/// 页面转换绑定的函数
/// </summary>
/// <param name="src"></param>
/// <param name="e"></param>
public void ChangePage(object src, PageChangedEventArgs e)
{
pager.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}