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() );
}



你可能感兴趣的:(分页)