ASP. NET true/false paging-true paging, asp.net true/false 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 download the AspNetPager control: 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. Shown as follows:
Further improve the paging prompt information. 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.
Improvement effect:
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 settings for the control above will automatically generate the corresponding code in VS, so we can also manually enter the code to set.
Okay, set the front-end, and then bind the data.
|
protectedvoidPage_Load(object sender, EventArgs e) { if(!Page .IsPostBack ) { string caid = Request.QueryString[caid]; DataTable dt =newNewsManager().SelectAllNewsByCaId(caid); anpCa.AlwaysShow =true; anpCa.PageSize =5; anpCa.RecordCount = dt.Rows.Count; intstartIndex = anpCa.PageSize *0; intendIndex = anpCa.PageSize *1; gvDataBind(caid, startIndex, endIndex); } } privatevoidgvDataBind(string caid,intstartIndex,intendIndex) { DataTable dt =newNewsManager().SelectPartNewsByCaId(caid, startIndex, endIndex); if(dt.Rows.Count !=0) { lblCategory.Text = dt.Rows[0][name].ToString(); // Display the corresponding category name for the category title } gvNew.DataSource = dt; gvNew.DataBind(); } protectedvoidanpCa_PageChanged(object sender, EventArgs e) { string caid =6; intstartIndex = anpCa.PageSize * (anpCa.CurrentPageIndex -1)+1; intendIndex = anpCa.PageSize * (anpCa.CurrentPageIndex); gvDataBind(caid, startIndex, endIndex); }} |
Code display for data query at Layer D
#region Take a pagination display of all news in the category according to the category ID
///
/// Get all news in the category according to the category ID
///
/// Category ID
///
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 (very important)
|
-- =============================================-- Author: Wang yingqun-- Create date:2014-8-10-- Description: displays all the news in the category by Page Based on the Data Category ID.-- =============================================ALTER PROCEDURE [dbo].[category_showpage] @caidint, @startIndexint, @endIndexintASBEGIN with 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@startIndexand@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.