asp.net page Summary of a data listing control (i) custom method paging and Pagedatasource class paging

Source: Internet
Author: User
Tags bind manual

In ASP.net, three powerful list controls are available: The GridView, DataList, and Repeater controls, but only the GridView control provides paging functionality. Although the DataGrid provides paging functionality, it appears to be limited in functionality, but we can take some of the GridView properties to get the status and add the home page, last feature button. If the speed efficiency is not very fastidious, by the DataGrid to manage the paging is good, pay the price is to take out the entire relevant data and then delete the selected page of data. The advantage is that the development speed is fast, do not need to write paging stored procedures. Therefore, if you need to pursue the implementation efficiency, and the data volume is larger than the proposed use of the GridView custom paging function. If the volume of data is not very large and requires more page functionality and style, the DataList and Repeater controls have a higher style customization relative to the GridView, so many times we prefer to use DataList or Repeater controls to display data. Now I use manual paging to compare these three controls. As follows:

(1). Manual paging using the GridView.

Control pagination by the Drop-down box.

Foreground code:

1<body>
2 <form id= "Form1" runat= "Server" >
3 <div>
4 <asp:gridview id= "Gvshow" runat = "Server" onpageindexchanging= "gvshow_pageindexchanging" allowpaging= "True" pagesize= "2" >
5 </asp: gridview>
6 <br/>
7 &nbsp;</div>
8 <asp:dropdownlist id= "DropDownList1" runat= "Server" autopostback= "True" onselectedindexchanged= "dropdownlist1_selectedindexchanged" >
9 </asp:d ropdownlist>
</form>
11</body>

Background code:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
  
Using System.Data.SqlClient;
  Public partial class _default:system.web.ui.page {static SqlConnection con;
  Static SqlDataAdapter SDA;
  static SqlCommand cmd;
  
  Static DataSet ds; protected void Page_Load (object sender, EventArgs e) {if (!
    IsPostBack) {Bind ();
    Remember this sentence can not be lost, otherwise the line number will be accumulated in the Drop-down box DropDownList1.Items.Clear ();
    for (int i = 1; i< gvshow.pagecount; i++) {DropDownList1.Items.Add (i.tostring ());
    }} private void Bind () {//gvshow.allowpaging = true;
    Gvshow.pagesize = 2;
    Gvshow.datasource =binddata ();
  Gvshow.databind (); } protected void DropDownList1_SelectedIndexChanged (object sender, EventArgs e) {//Critical code Gvshow.pageindex = Co Nvert. ToInt32 (DropDownList1.SelectedValue)-1;
  Bind (); } protected void Gvshow_pageindexchanging (object sender, Gridviewpageeventargs e) {gvshow.pageindex = E.newpagein
    Dex
  Bind (); private static void Init () {//database connection Statement con = new SqlConnection ("Data source=.;
    database= database name; uid= user id;pwd= user password ");
    ds = new DataSet (); try {con.
    Open ();
    Catch {throw new Exception ();
    The public static DataSet Binddata () {Init ();
    String sql = "SELECT * from book";
      try {SDA = new SqlDataAdapter (sql, con); Sda.
      Fill (ds, "book");
    return DS;
    Catch {throw new Exception (); }   }    }

Related Article

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.