The AspNetPager page records display instances, and the aspnetpager page records display instances.

Source: Internet
Author: User

The AspNetPager page records display instances, and the aspnetpager page records display instances.

In the final episode of the niugu video, a small example of the implementation of paging record display by an external control AspNetPager was not completed. It is understood that the paging display function is an important function in the software design, therefore, the unfinished work is completed here.

In the video, the pagination function of the gridview is a false pagination. Why? Because all the records in the database must be queried on each page, if the data volume is too large, it will cause great inconvenience. Therefore, the AspNetPager control is selected.

In fact, this control only provides a paging function, which does not display data. Therefore, it must be used together with the gridview to fully implement the paging function.

Of course, the use of the gridview control is used in videos. However, due to the repeated copying and pasting, it is difficult to recall how it was used later. In fact, this control has the following key points of attention:

1. When editing a column, you can select to edit it in the design view because the code is too long.

2. If you want to design a table style with css, you can convert the column into a custom template column, as shown in:

3. Application of the autogenericcolumns attribute

Now that you know how to use the controls, let's use them to create pages!

First, write the database query statement through the stored procedure, as follows:

Alter procedure [dbo]. [partPage] @ startIndex int, -- Query start record count @ endIndex int -- end record count ASBEGINwith temptbl as (SELECT ROW_NUMBER () OVER (order by id desc) AS row number, * from news -- sorting records in order and querying by row number) SELECT * FROM temptbl where row number between @ startIndex and @ endIndexEND

After the stored procedure is compiled, the code to be written at Layer D is as follows:

  public DataTable SelectByPage(int startIndex,int endIndex)        {            DataTable dt = new DataTable();            string cmdText = "partPage";            SqlParameter[] paras = new SqlParameter[]{                new SqlParameter ("@startIndex",startIndex ),                new SqlParameter ("@endIndex",endIndex )            };            dt = sqlhelper.ExecuteQuery(cmdText, paras, CommandType.StoredProcedure);            return dt;        }

The inconvenience caused by the code in sqlhelper is as follows:

/// <Summary> /// execute the query statement with parameters /// </summary> /// <param name = "SQL"> SQL statement </param>/ // <param name = "paras"> parameter </param> /// <returns> datatable </returns> public DataTable ExecuteQuery (string plain text, sqlParameter [] paras, CommandType ct) {DataTable dt = new DataTable (); cmd = new SqlCommand (cmdText, GetConn (); cmd. parameters. addRange (paras); cmd. commandType = ct; using (sdr = cmd. executeReader (CommandBehavior. closeConnection) {dt. load (sdr) ;}return dt ;}

All right, most of the background work is ready, and only the U-Layer Code is left:

Declaration: five pieces of news are displayed on each page according to the video in the design. If you can write in the code, you can write asp. pagesize = 5;

Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {DataTable dt = new DataTable (); dt = new NewsManager (). selectAll (); // select all news anp. recordCount = dt. rows. count; // total number of records // start binding record int startIndex = anp. startRecordIndex; // number of start records int endIndex = anp. endRecordIndex; // Number of end records dt = new NewsManager (). selectByPage (startIndex, endIndex); gvNews. dataSource = dt; gvNews. dataBind () ;}} protected void anp_PageChanged (object sender, EventArgs e) {Response. write ("Number of start records:" + anp. startRecordIndex + "Number of end records:" + anp. endRecordIndex );}

Now, the basic framework has been implemented. Let's take a look at the effect!


Looks pretty good, right ???


How to Use the AspNetPager paging control in vs08 to paging the dynamic query results is best to have an instance

First, <% @ Register Assembly = "AspNetPager" Namespace = "Wuqi. Webdiyer" TagPrefix = "webdiyer" %> must be placed in the second line of the aspx file.
Then <webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" Width = "100%" UrlPaging = "true"
ShowPageIndexBox = "Always" PageIndexBoxType = "DropDownList" TextBeforePageIndexBox = ":"
HorizontalAlign = "right" PageSize = "12" OnPageChanged = "AspNetPager1_PageChanged"
EnableTheming = "true">
</Webdiyer: AspNetPager>
Put it at the location of the page you want.

Finally, bind AspNetPager1.RecordCount to the page_load event of cs = the total number of information you need to retrieve.

If you want to enable refreshing, you can use the jq callback to automatically refresh the display.

I used the ASPnetpager page. Why is all data loaded on the next page displayed on three data points after my search criteria are met?

You use the post method for submission. You can change it to the get method.
The post method can also be used for submission. You must write down the parameters and pass the corresponding parameters during paging. This is useful.

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.