Use the ojectdatasource data source to bind the listview efficient Paging

Source: Internet
Author: User

Cause:

The traditional objectdatasource is used as the data source. If you bind a listview, you can insert, delete, update, delete, or pagination data without writing a line of code! Exceptional power! However, the default paging mode of listview is to retrieve all data from the database and display the data after pagination Based on the page number, so what if we can't get specific data from a page? The answer is yes!

Technical steps for efficient paging:

Based on your original program:

Step 1: Create a strongly Typed Dataset

Add two functions:

The first one is: or the total number of data entries in the database querycount

Select count (*) from t_news

The second is: Get a piece of data in the database getpageddata

Select * from

(Select ID, title, MSG, createdate, row_number () over (order by ID) rownum from DBO. t_news) T

Where T. rownum> @StartrowindexAnd T. rownum <= @Startrowindex+ @Maximumrows

A warning is displayed, indicating that the row_number () function cannot be generated but the function is not affected. The result is


Because row_number () cannot be generated, we need to add the parameter of the second function! Function right-click attribute


Final Effect


Step 2: configure the data source objectdatasource for efficient Paging

Reconfigure the data source and select the getpageddata method you just added!

Delete the automatically generated select Method


Add a method to obtain the total number of data manually:

Selectcountmethod = "querycount"

Enable the paging function of the Data source:


Set the number of datapager pages in listview to 10. OK!

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.