This period of time to read the ASP. NET video, but feel that their study does not seem to consolidate good, and then in the library borrowed a few books about ASP. I feel really good about the basic small demo, but I know that only the real use can be harvested, and their own awareness is still to Further study, in this part of the study oneself also is to have a basic understanding of the page, also use it to make out of a few basic demo, then we look at this control for the true and false pagination of some of the use of methods.
I. What is true and false paging
1. False paging:
False paging although the interface to achieve paging, but he did not implement paging, every time you click on the number of pages from the database to tell all the data and then re-check, that is, every time you query from the database, it will affect his query speed, So fake paging is the implementation of pagination on the interface, but there is still no real paging.
2. True paging:
Then we know that if you want to really realize paging, is to just query out the data you want to the page, so you can reduce the amount of data per query and can also improve the efficiency of the query, the real implementation of the page to look up a page.
Two. Basic implementation
1. Fake page break
The video in our video has a long history so when we learned it here, the control has changed its name, but it is still in the same way, or it has to go through so many steps to change his AllowPaging property to true in the GridView,,1> Then set the pagesize to the number you want to page, and then the next step is to bind the control to the database
protected void Page_Load (object sender, EventArgs e) {//page is loaded for the first time if (! Page.IsPostBack) {//bind data Gridview1.datasource = MyData (); Gridview1.databind (); }} protected void Gridview1_pageindexchanging (object sender, Gridviewpageeventargs e) { Gridview1.pageindex = E.newpageindex; DataTable dt = MyData (); Gridview1.datasource = DT; Gridview1.databind (); } private static DataTable MyData () {SqlConnection con = new SqlConnection ("server= .; Database=northwind;uid=sa;password=gss123 "); Con. Open (); String strcmd = "SELECT * from comment"; SqlCommand cmd = new SqlCommand (Strcmd,con); SqlDataReader SDR = cmd. ExecuteReader (); DataTable dt=new DataTable (); Dt. Load (SDR); Con. Close (); return DT; } }
The above is the data binding for false paging.
2. True pagination
True paging but it takes a little effort, true paging is required to aspnetpaper this third-party control, need to download his DLL file and then drag to the toolbox and then use it, he is a tool to turn the page
protected void Page_Load (object sender, EventArgs e) {if (! Page.IsPostBack) {//When the form is clocked, the starting data number is 0, the number of information bars for the terminating data number is per page int intstartindex = ANP . PageSize * 0; int intendindex = ANP. PageSize * 1; <span style= "color: #ff0000;" ><strong> ANP. RecordCount = Myalldata (). Rows.count;</strong></span>//bind data Gridview1.datasource = Mypartdata (Intstar Tindex, Intendindex); Gridview1.databind (); }}///<summary>//Change the number of pages displayed///</summary>//<param Nam E= "Sender" ></param>//<param name= "E" ></param> protected void anp_pagechanged (obj ECT sender, EventArgs e) {//start data Number = information capacity per page * (current page-1) +1;//Example: Sixth page, per page 5, sixth page starting data =5*5+1=2 6; int INTSTARTINDEX=ANP. PageSize * (ANP. Currentpageindex-1) +1; int intendindex = ANP. PageSize * ANP. CurrentPageIndex; Gridview1.datasource = Mypartdata (Intstartindex,intendindex); Gridview1.databind (); }///<summary>/////</summary>//<param name= "Intstartindex" > Start Data Number </param>//<param name= "Intendindex" > End data Number </param>//<returns> table Lattice </returns> private static DataTable mypartdata (int intstartindex,int intendindex) { SqlConnection con = new SqlConnection ("server=.; database=newssystem;uid=sa;password=123456 "); Con. Open (); String strcmd = "SELECT * from comment"; SqlCommand cmd = new SqlCommand (Strcmd,con); SqlDataReader SDR = cmd. ExecuteReader (); DataTable dt=new DataTable (); Dt. Load (SDR); Con. Close (); return DT; }//<summary>///Full Enquiry//</summary>//<returns></returns> privat e static DataTable Myalldata () {SqlConnection con = new SqlConnection ("server=.; Database=northwind;uid=sa;password=gss123 "); Con. Open (); String CMD = "SELECT * from comment"; SqlCommand cmd = new SqlCommand (cmd, con); SqlDataReader SDR = cmd. ExecuteReader (); DataTable dt = new DataTable (); Dt. Load (SDR); Con. Close (); return DT; } }
After this period of study I learned about the true and false page of the matter so, in the future to continue to learn some of his things, and I understand that sometimes they can not go through the time to see how others are doing, but do not use the full reference, but also to have their own experience.
ASP (four)-using the GridView to realize the true and false pagination