asp.net Repeter 控件怎么写 首页 上一页 1 2 3 4 5 6 7 8 9 下一页 末页 分页?
不用aspnetpager这个代码写了不显示什么玩意啊。。而且Access数据库要取得全部数据才能分页。。...
不用 aspnetpager 这个代码写了不显示什么玩意啊。。而且Access 数据库要取得全部数据才能分页。。
展开
2个回答
展开全部
添加一个web用户控件,Paper.ascx
代码
public event PageChangedEventHandler PageChanged;
//属性
/// <summary>
/// 一页显示数据数
/// </summary>
public int Pagesize
{
get;
set;
}
/// <summary>
/// 当前页索引
/// </summary>
public int PageIndex
{
get
{
if (string.IsNullOrEmpty(ViewState["PageIndex"].ToString()))
{
return 1;
}
else
{
return int.Parse(ViewState["PageIndex"].ToString());
}
}
set
{
ViewState["PageIndex"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
//监视事件
protected void OnPageChange(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageChanged(sender, e);
}
}
public PagedDataSource BindData(DataTable dtSource)
{
//数据源
PagedDataSource pageDS_gg = new PagedDataSource();
//设置数据源
pageDS_gg.DataSource = dtSource.DefaultView;
//设置允许分页
pageDS_gg.AllowPaging = true;
//每页显示数
pageDS_gg.PageSize = Pagesize;
//显示总共页数
lbl_TotalCount.Text = pageDS_gg.PageCount.ToString();
//设置当前页的索引
int nCurrectPage = PageIndex;
if (nCurrectPage > pageDS_gg.PageCount)
{
nCurrectPage = pageDS_gg.PageCount;
}
//当前页所引为页码-1
pageDS_gg.CurrentPageIndex = nCurrectPage - 1;
//显示当前页码
lbl_CurrentPage.Text = nCurrectPage.ToString();
//初始化
hl_First.Enabled = hl_Last.Enabled = hl_Next.Enabled = hl_Pievious.Enabled = true;
//如果是第一页,不显示连接
if (pageDS_gg.IsFirstPage)
{
hl_Pievious.Enabled = false;
}
//如果是最后一页,不显示连接
if (pageDS_gg.IsLastPage)
{
hl_Next.Enabled = false;
}
return pageDS_gg;
}
#region 翻页
protected void hl_First_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex = 1;
this.PageChanged(sender, e);
}
}
protected void hl_Pievious_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex -= 1;
this.PageChanged(sender, e);
}
}
protected void hl_Next_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex += 1;
this.PageChanged(sender, e);
}
}
protected void hl_Last_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex = int.Parse(lbl_TotalCount.Text);
this.PageChanged(sender, e);
}
}
protected void hl_go_Click(object sender, EventArgs e)
{
PageIndex = int.Parse(txt_page.Text);
this.PageChanged(sender, e);
}
#endregion
}
}
代码
public event PageChangedEventHandler PageChanged;
//属性
/// <summary>
/// 一页显示数据数
/// </summary>
public int Pagesize
{
get;
set;
}
/// <summary>
/// 当前页索引
/// </summary>
public int PageIndex
{
get
{
if (string.IsNullOrEmpty(ViewState["PageIndex"].ToString()))
{
return 1;
}
else
{
return int.Parse(ViewState["PageIndex"].ToString());
}
}
set
{
ViewState["PageIndex"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
//监视事件
protected void OnPageChange(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageChanged(sender, e);
}
}
public PagedDataSource BindData(DataTable dtSource)
{
//数据源
PagedDataSource pageDS_gg = new PagedDataSource();
//设置数据源
pageDS_gg.DataSource = dtSource.DefaultView;
//设置允许分页
pageDS_gg.AllowPaging = true;
//每页显示数
pageDS_gg.PageSize = Pagesize;
//显示总共页数
lbl_TotalCount.Text = pageDS_gg.PageCount.ToString();
//设置当前页的索引
int nCurrectPage = PageIndex;
if (nCurrectPage > pageDS_gg.PageCount)
{
nCurrectPage = pageDS_gg.PageCount;
}
//当前页所引为页码-1
pageDS_gg.CurrentPageIndex = nCurrectPage - 1;
//显示当前页码
lbl_CurrentPage.Text = nCurrectPage.ToString();
//初始化
hl_First.Enabled = hl_Last.Enabled = hl_Next.Enabled = hl_Pievious.Enabled = true;
//如果是第一页,不显示连接
if (pageDS_gg.IsFirstPage)
{
hl_Pievious.Enabled = false;
}
//如果是最后一页,不显示连接
if (pageDS_gg.IsLastPage)
{
hl_Next.Enabled = false;
}
return pageDS_gg;
}
#region 翻页
protected void hl_First_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex = 1;
this.PageChanged(sender, e);
}
}
protected void hl_Pievious_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex -= 1;
this.PageChanged(sender, e);
}
}
protected void hl_Next_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex += 1;
this.PageChanged(sender, e);
}
}
protected void hl_Last_Click(object sender, EventArgs e)
{
if (PageChanged != null)
{
PageIndex = int.Parse(lbl_TotalCount.Text);
this.PageChanged(sender, e);
}
}
protected void hl_go_Click(object sender, EventArgs e)
{
PageIndex = int.Parse(txt_page.Text);
this.PageChanged(sender, e);
}
#endregion
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询