To undertake the last blog "net True and False page - false paging": http://blog.csdn.net/u010773667/article/details/38845009, continue to explain the ASP true pagination of. NET true and False pages.
True pagination
When the amount of data is too large, there are tens of thousands of or even a hundred thousand of data, each time from the database to remove all the data will reduce the query efficiency, the system is running slowly, there may be stuck, then false paging will appear very impersonal, so there is the need for true paging.
as summarized in the previous blog post, "True" is relative to the "false" existence, that is, not entangled, completely disconnected from the root, in this case, based on the query conditions, only from the database to extract the necessary parts, suitable for big data. The implementation of true paging is based on third-party control Aspnetpager.
Aspnetpagercontrol is a third-party free open source control based on . NET , with the advantages of high efficiency, easy to use and complete function. It makes up for the shortcomings of the GridView built-in paging and the Pagedatasource class auxiliary paging, separates the paging data logic and the page UI , and is very advantageous to the implementation of SQL paging.
First you need to download the Aspnetpager control: http://www.webdiyer.com/downloads/
Referencing the Aspnetpager control in vs , you are welcome to add a selection section to "vs add Ajax" in the blog post (there is a picture of the truth), which is not mentioned here: http:/ /blog.csdn.net/u010773667/article/details/38518461
First drag and drop a GridView control in the Web form to display the data, select the aspnetpager control and drag it to the Web The corresponding location of the form is used for paging settings. Shown below:
Further improvements to the paging prompt information. With the spnetpager Control selected, a small button appears in the lower right corner, click Open to set the navigation button display text
Improved effect:
Set page index text or drop-down boxes
The effect of improvement is shown in:
If you want to display more specific, you can customize how the information area is displayed and the content settings
All of the above settings for the control will automatically generate the corresponding code in VS , so we can also set it by manually entering the code.
Well, set up the front desk, and then we'll have data binding.
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) {Datatab Le dt = new Newsmanager (). Selectpartnewsbycaid (CAID, StartIndex, EndIndex); if (dt. Rows.Count! = 0) {lblcategory.text = dt. rows[0]["Name"]. ToString (); Make the category title display the appropriate category name} 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); }}
Part of the code display in the D -tier data query
</pre></p><p></p><pre class= "html" name= "code" >
</pre><span style= "font-family: Chinese italics; font-size:14pt;" ></span><pre class= "html" name= "code" > #region out of all news pages under that category based on category ID //<summary>// /Remove all news under this category by 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 procedures (very important)
--=============================================--Author: Wang Yingqun--Create date:2014-8-10--Description: The pagination of all news under this category is taken with the category ID-=============================================alter PROCEDURE [dbo]. [Category_showpage] @caid int, @startIndex int, @endIndex intasbeginwith temptable as ( select Row_number () over ( ORDER BY id DESC) as line number, * from ( select N.id,n.titile,n.createtime,c.[name],n.caid from news n INNER join cat Egory C on N.caid =c.id and N.caid [e-mail protected] ) as AA) SELECT * from TempTable where line number between @startIndex and @endIndex END
Post-operation effects see:
Note: My program has a parameter (category ID), in the process of dynamic changes in the page index needs to be re-obtained, which I did not realize, I hope that the small partners can help me, thank you !
In conjunction with the previous blog post, false paging is suitable for situations where the amount of data is relatively small, and true paging is appropriate for large data volumes. The use of true and false paging, for our reading burden.
Asp. NET True and False page-real pagination