ASP. NET true/false paging-true paging, asp.net true/false Paging

Source: Internet
Author: User

ASP. NET true/false paging-true paging, asp.net true/false Paging
Zookeeper

Post on ASP. NET true/false pagination-false pagination: Success.

 

Real Paging



When the data volume is too large and there are tens of thousands or even tens of thousands of pieces of data, every time you retrieve all the data from the database, the query efficiency will be reduced, the system runs slowly, and may be stuck, at this time, fake pages will appear very unfriendly, so there is a need for real pages.


As summarized in the previous blog post, "true" exists relative to "false", that is, it does not disconnect the wire, and is completely disconnected from the root. In this case, it is displayed according to the query conditions, extracts only the required parts from the database, which is suitable for big data. The implementation of real paging requires the use of the third-party control AspNetPager.



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.

 

First you need to download the AspNetPager control, download the DLL file: http://www.webdiyer.com/downloads


REFERENCE The AspNetPager control in VS, welcome to refer to the blog "VS add Ajax" to add the selection part (there is a picture of the truth), here not to repeat: http://blog.csdn.net/u010773667/article/details/38518461


First, drag and drop a gridview control in the web form to display data. Select the AspNetPager control and drag it to the corresponding position of the web form for paging settings. Select the spNetPager control. A small button is displayed in the lower right corner. Click Open to set the text displayed in the navigation button.



Effect after running:


Set page index text or drop-down box


For the improvement effect, see:


If you want to display more specific information, you can customize the display mode and content settings of the information area.



All the preceding settings of the control will automatically generate the corresponding code in VS. You can also manually enter the code to set them.


Okay, set the foreground, and then bind the data (Note: caid = 6 is bound to method anpCa_PageChanged (). here you need to obtain the category ID again. I have not solved this problem... Hope you can kindly remind me)


Protected void Page_Load (object sender, EventArgs e) {if (! Page. isPostBack) {string caid = Request. queryString ["caid"]; DataTable dt = new NewsManager (). selectAllNewsByCaId (caid); anpCa. alwaysShow = true; anpCa. pageSize = 5; anpCa. recordCount = dt. rows. count; int startIndex = anpCa. pageSize * 0; int endIndex = anpCa. pageSize * 1; gvDataBind (caid, startIndex, endIndex) ;}} private void gvDataBind (string caid, int startIndex, int endIndex) {DataTable dt = New NewsManager (). SelectPartNewsByCaId (caid, startIndex, endIndex); if (dt. Rows. Count! = 0) {lblCategory. text = dt. rows [0] ["name"]. toString (); // display the corresponding category name in the category title} gvNew. dataSource = dt; gvNew. dataBind ();} protected void anpCa_PageChanged (object sender, EventArgs e) {string caid = "6"; int startIndex = anpCa. pageSize * (anpCa. currentPageIndex-1) + 1; int endIndex = anpCa. pageSize * (anpCa. currentPageIndex); gvDataBind (caid, startIndex, endIndex );}}


Code display for data query at Layer D

</pre></p><p></p><pre class="html" name="code">
</Pre> <span style = "font-family: 文; font-size: 14pt; "> </span> <pre class =" html "name =" code "> # region retrieves the page display of all news in this category based on the category ID. // <summary> /// retrieve all news under the category based on the category ID /// </summary> /// <param name = "caId"> category ID </param> /// <returns> </returns> public DataTable SelectPartNewsByCaId (string caId, int startIndex, int endIndex) {DataTable dt = new DataTable (); SqlParameter [] paras = new SqlParameter [] {new SqlParameter ("@ caId", caId ), new SqlParameter ("@ startIndex", startIndex), new SqlParameter ("@ endIndex", endIndex)}; dt = sqlhelper. executeQuery ("dbo. category_showpage ", paras, CommandType. storedProcedure); return dt ;}# endregion


Stored Procedure (important)


-- ===================================================== ====== -- Author: wang yingqun -- Create date: 2014-8-10 -- Description: retrieve the page display of all news under the category with the data category ID -- ====================== ============================== alter procedure [dbo]. [category_showpage] @ caid int, @ startIndex int, @ endIndex intASBEGINwith temptable as (select ROW_NUMBER () over (order by id desc) as row number, * from (select n. id, n. titile, n. createTime, c. [name], n. caId from news n inner join category c on n. caId = c. id and n. caId = @ caid) as aa) select * from temptable where row number between @ startIndex and @ endIndex END

After running, see:




Note: I have a parameter (Category ID) in my program, and I need to obtain it all the time when the page index changes dynamically. I have not implemented this. I hope my friends can help me, thank you!



Combined with the previous blog post, fake paging is suitable for the case where the data volume is relatively small, while real paging is suitable for the case where the data volume is large. The use of true and false pagination reduces our reading workload.


Whether AspNetPager is a real page or a false page

I think you are wrong. All paging data is taken out of the database. only when the paging statement of your database is well written, you can find a small amount of data, which is a good paging. if it is not well written, all the data will be retrieved and then paged by the index of the paging control. the AspNetPager control is only a tool for paging convenience. There is no real or false paging. database statements are the most important

New users help ASPNET. Let me see if my paging method is real paging or false paging.

The query statement for false pages is generally select *, row r from table where r> beginPageSize and r <endPageSize
BeginPageSize, endPageSize is two input parameters

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.