AspNetAjaxPager,Asp.Net通用无刷新Ajax分页控件,支持(2)


//======================================================================
// 公司名称: 野人网络工作室()
// 机器名称: WWW-BBE63F97A80
// 注册组织名: Lenovo (Beijing) Limited
// CLR版本: 2.0.50727.1433
// 文件名称: Default.aspx.cs
// 创建者: 邵龙
// 创建时间: 2009-4-4 16:29:49
// 程序版本: 1.0版
// 功能描述: AspNetAjaxPager使用Demo
// 修改记录:
//======================================================================
using System;
using System.Data;
using System.Configuration;
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 System.Data.OleDb;
using AspNetAjaxPager.Delegate;
namespace Demo
{
public partial class _Default : System.Web.UI.Page
{
private OleDbConnection conn;
private OleDbCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.BindData(this.Pager1.CurrentPageIndex, this.Pager1.PageSize);
}
else
{
///点击分页导航时由控件代理对象触发绑定事件重新显示数据
this.Pager1.OnPageIndexChanged = new PageIndexChangedDelegate(BindData);
}
}
/// <summary>
/// 绑定Repeater数据
/// </summary>
/// <param></param>
/// <param></param>
public void BindData(int PageIndex, int PageSize)
{
int intStartIndex = (PageIndex - 1) * PageSize + 1;
int intEndIndex = PageIndex * PageSize;
conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/app_data/db.mdb");
cmd = conn.CreateCommand();
conn.Open();
///此部分可以换成存储过程分页,对控件没有任何影响
cmd.CommandText = "select count(*) from students";
int totalCount = (int)cmd.ExecuteScalar();
cmd.CommandText = string.Format("select * from students where id >= {0} and id <= {1}", intStartIndex, intEndIndex);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd.CommandText, conn);
da.Fill(ds);
this.Pager1.RecordCount = totalCount;
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
}
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/d74527b3abebfc7cc49cc2f336d4e037.html