asp. net Control DataList Paging Usage

  • 2021-07-22 09:30:02
  • OfStack

This article illustrates the asp. net control DataList paging usage. Share it for your reference, as follows:


protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
   ViewState["Page"] = 0;
   Bangding();
  }
}
// Bind data 
public void Bangding()
{
  PagedDataSource pds = new PagedDataSource();
  pds.DataSource = MerchandiseManager.GetList("");
  pds.AllowPaging = true;
  pds.PageSize = 5; // Number of records per page 
  pds.CurrentPageIndex = Pager;// Current page 
  lblCurrPage.Text = " No. 1 " + (pds.CurrentPageIndex + 1).ToString() + " Page   Altogether " + pds.PageCount.ToString() + " Page ";
  SetEnable(pds);// Valid strong state of upper and lower page buttons 
  dlistMerchand.DataSource = pds;
  dlistMerchand.DataBind();
}
private int Pager
{
  get
  {
   return (int)ViewState["Page"];
  }
  set
  {
   ViewState["Page"] = value;
  }
}
// Under 1 Page 
protected void LinkButton1_Click(object sender, EventArgs e)
{
  Pager++;
  Bangding();
}
// Upper 1 Page 
protected void LinkButton2_Click(object sender, EventArgs e)
{
  Pager--;
  Bangding();
}
// Valid strong state of upper and lower page buttons 
private void SetEnable(PagedDataSource pds)
{
  btnShang.Enabled = true;
  btnXia.Enabled = true;
  if (pds.IsFirstPage)
  {
   btnShang.Enabled = false;
  }
  if (pds.IsLastPage)
  {
   btnXia.Enabled = false;
  }
}

For more readers interested in asp. net, please check the topics on this site: "asp. net String Operation Skills Summary", "asp. net Operation XML Skills Summary", "asp. net File Operation Skills Summary", "asp. net ajax Skills Summary" and "asp. net Cache Operation Skills Summary".

I hope this paper is helpful to everyone's asp. net programming.


Related articles: