Repeater控件的分页问题

Repeater控件的分页问题
protected System.Web.UI.WebControls.Repeater rptFramework
private void Page_Load(object sender, System.EventArgs e)
{
  //建立DataSet
  (该部分省略)

  rptFramework.DataSource = myDataSet;
  rptFramework.DataBind();
  Session["page"] = 1;
 
 //将Repeater所有条目隐藏
  int i = 0 ;
  for( i = 0 ; i < rptFramework.Items.Count ; i++ )
  {
    rptFramework.Items[i].Visible = false;
  }
  //Repeater控件的页面大小
  int intPageSize = 10;
 
 //rptFramework控件的当前页索引(1起始)
  int intCurrentPageIndex = 0 ;
  if ( Request.QueryString["page"] == null || Convert.ToInt32( Request.QueryString["page"] ) == 0 )
  {
    Session["page"] = 1 ;
  }
  else
  {
    Session["page"] = Convert.ToInt32( Request.QueryString["page"] );
  }
  intCurrentPageIndex = Convert.ToInt32( Session["page"] );
  //上一页按钮屏蔽
  if ( Convert.ToInt32( Session["page"] ) == 1 )
  {
    btnPre.Enabled = false;
  }
 
 //rptFramework控件的当前游标索引(1起始)
  int intCurrentItemIndex = 1 ;
  intCurrentItemIndex = intPageSize * ( intCurrentPageIndex - 1 ) + 1 ;
  //下一页按钮屏蔽
  if ( (rptFramework.Items.Count - intCurrentItemIndex) < intPageSize )
  {
    btnNext.Enabled = false;
  }
  //设置窗体加载时的默认视图
  if ( rptFramework.Items.Count > intPageSize )
  {
    for (i = intCurrentItemIndex ; i < GetMin( rptFramework.Items.Count , intCurrentItemIndex + intPageSize ) ; i++ )
  {
  rptFramework.Items[i-1].Visible = true;
  }
}
//取两个数值中较小的值,但是不改变原数值大小
private int GetMin( int a , int b )
{
  int c ;
  if ( a > b )
  {
    c = b;
  }
  else
  {
    c = a;
  }
  return c;
}
//点击上一页按钮
private void btnPre_Click(object sender, System.EventArgs e)
{
  int intPrePageIndex = 2;
  if ( Convert.ToInt32( Session["page"] ) != 1 )
  {
    intPrePageIndex = Convert.ToInt32( Session["page"] ) - 1;
  }
  else
  {
    intPrePageIndex = 1;
  }
  Response.Redirect( "jggk.aspx?page=" + intPrePageIndex.ToString() );
}
//点击下一页按钮
private void btnNext_Click(object sender, System.EventArgs e)
{
  int intNextPageIndex = Convert.ToInt32( Session["page"] ) + 1;
  Response.Redirect( "jggk.aspx?page=" + intNextPageIndex.ToString() );
}



转载于:https://www.cnblogs.com/qinfei/archive/2005/11/03/268226.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值