Controls usage reference: DataList and Repeater controls display by PAGE

Source: Internet
Author: User
Implement using the PagedDataSource class

                 Pagination of DataList and Repeater controls   Asp.net provides three powerful list controls: the DataGrid, DataList, and Repeater controls, which have higher style customization compared with the DataGrid, DataList, and Repeater controls, many times we like to use the DataList or Repeater control to display data. However, Repeater and DataList do not have the paging function and are sometimes inconvenient.

   The PagedDataSource class encapsulates the properties of the DataGrid control so that the DataGrid Control can execute pagination. It is a data container. We first read the data from the database and put it in this container, then, set the container property to retrieve part of the data on the page to be displayed, and then bind the data to the display control on the page.

   The following example shows the data paging list implemented by the Repeater control and HyperLink control combined with the PagedDataSource class.

  

Source code for data function implementation:

// Reference the class used for paging
PagedDataSource PPS = new PagedDataSource ();
Pds. DataSource = dt. DefaultView; // sets the data source (DataTable type)
PPS. AllowPaging = true;
// Number of lines displayed on the page
PPS. PageSize = 18;

// Set the current page
If (Pageindex <1) Pageindex = 1;
PPS. CurrentPageIndex = Pageindex-1;

Rpt_NewsList.DataSource = pds;
Rpt_NewsList.DataBind ();

// Display the page number
Ltl_RecordCount.Text = PPS. performancecount. ToString ();
Ltl_PageCount.Text = maid. PageCount. ToString ();
Ltl_Pageindex.Text = Pageindex. ToString ();
Ltl_Jump.Text = Jump_List (PPS. PageCount, Pageindex, L_Manage );

// Display up and down pages (the parameters following the URL are defined as needed)
Lbn_First.ToolTip = "Jump to homepage ";
Lbn_First.NavigateUrl = Request. CurrentExecutionFilePath+ "? Org_ID = "+ L_Manage +" & page = 1 ";
Lbn_Prev.ToolTip = "Jump to previous page ";
Lbn_Prev.NavigateUrl = Request. CurrentExecutionFilePath+ "? Org_ID = "+ L_Manage +" & page = "+ (Pageindex-1 );
Lbn_Next.ToolTip = "Jump to next page ";
Lbn_Next.NavigateUrl = Request. CurrentExecutionFilePath+ "? Org_ID = "+ L_Manage +" & page = "+ (Pageindex + 1 );
Lbn_Last.ToolTip = "Jump to the last page ";
Lbn_Last.NavigateUrl = Request. CurrentExecutionFilePath+ "? Org_ID = "+ L_Manage +" & page = "+ pds. PageCount. ToString ();

// Determine the link Display Mode
If (Pageindex <= 1 & tp.pagecount <= 1)
{
    Lbn_First.NavigateUrl = "";
    Lbn_Prev.NavigateUrl = "";
    Lbn_Next.NavigateUrl = "";
    Lbn_Last.NavigateUrl = "";
}
If (Pageindex <= 1 & tp.pagecount> 1)
{
    Lbn_First.NavigateUrl = "";
    Lbn_Prev.NavigateUrl = "";
}
If (Pageindex> = maid. PageCount)
{
    Lbn_Next.NavigateUrl = "";
    Lbn_Last.NavigateUrl = "";
}

/// <Summary>
/// Calculate the page Jump
/// </Summary>
/// <Param name = "Pagecount"> page count </param>
/// <Returns> string </returns>
Private string Jump_List (int Pagecount, int Pageindex, long L_Manage)
{
StringBuilder sb = new StringBuilder ();
Sb. Append ("<select id = \" Page_Jump \ "name = \" Page_Jump \ "onchange = \" window. location = '"+ Request. CurrentExecutionFilePath+ "? Page = '+ this. options [this. selectedIndex]. value +' & Org_ID = "+ L_Manage +" '; \ "> ");
For (int I = 1; I <= Pagecount; I ++)
{
If (Pageindex = I)
Sb. Append ("<option value = '" + I + "'selected>" + I + "</option> ");
Else
Sb. Append ("<option value = '" + I + "'>" + I + "</option> ");
}
Sb. Append ("</select> ");

Return sb. ToString ();
}

Dynamic Display

Some public attributes of the PagedDataSource class (omitted)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.