The most basic usage of the AspNetPager control is the aspnetpager control.

Source: Internet
Author: User

The most basic usage of the AspNetPager control is the aspnetpager control.

The AspNetPager control is a third-party free open-source Control Based on. net. It has the advantages of efficient development, convenient use, and complete functions. It makes up for the shortcomings of the built-in pagination and PageDatasource auxiliary paging of the GridView. It separates the paging data logic from the page UI, which is very helpful for the implementation of SQL paging. The following is only a basic usage to help beginners get started.

Go to the AspNetPage official website to download the control: Click to open the link

After downloading and decompressing, there is an AspNetPager. dll file, which is the control we want to use. There is also an AspNetPager. xml file, which is a corresponding document and has two main functions: first, it is used by developers to embed instructions for use in code smart prompts, the second is for Automatic Document generation tools to generate documents. We put these two files together under the binfile of the website, and then add the control in the toolbox of Visual Studio 2008 Express. Drag a GridView and an AspNetPager control to the page.

This is the most important and basic usage of the AspNetPager control. The Code is as follows:

Code related to the Default. aspx file:

[Html]View plaincopy
  1. <Asp: GridView ID = "GridView1" runat = "server">
  2. </Asp: GridView>
  3. <Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" PageSize = "20"
  4. Onpagechanging = "AspNetPager1_PageChanging">
  5. </Webdiyer: AspNetPager>


Code related to the Default. aspx. cs file:

[Csharp]View plaincopy
  1. Protected void Page_Load (object sender, EventArgs e)
  2. {
  3. If (! IsPostBack)
  4. DisplayData (1, AspNetPager1.PageSize );
  5. }
  6. Private void DisplayData (int pageIndex, int pageSize)
  7. {
  8. SQLiteData md = new SQLiteData ();
  9. AspNetPager1.RecordCount = md. ExecuteScalar <int> ("select count (*) from city ");
  10. DataTable dt = md. FillDataTable (string. Format ("select * from city limit {0}, {1}", (pageIndex-1) * pageSize, pageSize ));
  11. Md. Close ();
  12. GridView1.DataSource = dt;
  13. GridView1.DataBind ();
  14. }
  15. Protected void AspNetPager1_PageChanging (object src, PageChangingEventArgs e)
  16. {
  17. DisplayData (e. NewPageIndex, AspNetPager1.PageSize );
  18. }

First, set the PageSize attribute in the aspx file, indicating that the size of each page is 20 records. Then the total number of records in the background is RecordCount, and the current page number is e. NewPageIndex. Among them, the DisplayData method is very important, and the Implementation here is concise. When you access the page for the first time, 1st pages and 20 records on each page are displayed. When you select another page, the page e. NewPageIndex and 20 records on each page are displayed. This example uses the SQLite database and supports the limit keyword. Therefore, the paging logic is relatively simple. It should be noted that the SQLiteData database operation class compiled by myself is used here, and the reader can rewrite it into a native ADO.net operation, which is not very difficult.

Last display:


The AspNetPager control has powerful functions. It only introduces the most basic usage and will introduce other functions in the future.


How to Use the AspNetPager Control

This is a paging control that only provides the paging function. You can change the page control at most ..
How to display your data depends on the control you are bound ..
You can only modify the attributes of the bound control by yourself .. ,.

How to Use the aspnetpager paging Control

The control is just a control. You can use it for paging.
It's just easy to look professional,
You must write stored procedures or SQL statements by yourself.

Related Article

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.