AspNetPager + GridView paging implementation

Source: Internet
Author: User

1. The Framework is. NET Framework 4.0
2. There are three parts in total: front-end page design code, front-end page program code, css style
3. DB and SQLHelper are used for database connection operations)
:
 
 

Front-end page design code
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "TestWebSite. Default" %>

<% @ Register assembly = "AspNetPager" namespace = "Wuqi. Webdiyer" tagprefix = "webdiyer" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Link href = "Styles/Paging.css" rel = "stylesheet" type = "text/css"/>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>

<Asp: GridView ID = "GridView1" runat = "server" Height = "261px" Width = "737px"
CellPadding = "4" ForeColor = "#333333" GridLines = "None">
<AlternatingRowStyle BackColor = "White"/>
<EditRowStyle BackColor = "# 2461BF"/>
<FooterStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>
<HeaderStyle HorizontalAlign = "Left" BackColor = "#507CD1" Font-Bold = "True"
ForeColor = "White"/>
<PagerStyle BackColor = "# 2461BF" ForeColor = "White" HorizontalAlign = "Center"/>
<RowStyle BackColor = "# EFF3FB"/>
<SelectedRowStyle BackColor = "# D1DDF1" Font-Bold = "True" ForeColor = "#333333"/>
<SortedAscendingCellStyle BackColor = "# F5F7FB"/>
<SortedAscendingHeaderStyle BackColor = "#6D95E1"/>
<SortedDescendingCellStyle BackColor = "# E9EBEF"/>
<SortedDescendingHeaderStyle BackColor = "# 4870BE"/>
</Asp: GridView>

</Div>
<Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server"
Onpagechanged = "AspNetPager1_PageChanged" CssClass = "anpager"
CurrentPageButtonClass = "cpb" FirstPageText = "Homepage" LastPageText = "last page"
NextPageText = "" PrevPageText = "">
</Webdiyer: AspNetPager>
</Form>
</Body>
</Html>

Foreground page program code
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using TestWebSite. Utilities;
Using System. Data;
Using System. Data. SqlClient;
Using Wuqi. Webdiyer;

Namespace TestWebSite
{
Public partial class Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
// Call the BIND page and the GridView
BindGridView ();
}
}

//// Bind the pagination and GridView Methods
Private void BindGridView ()
{
// Query statement
String sequal = "select StandardName as standard name, MakeUpItem as compensation item, Unit as Unit ,"
+ "Cast (UnitPrice as decimal () as unit price, cast (StandRate as decimal ()"
+ "New rate, Type as classification from Standard ";
// Obtain a data table
DataTable dt =
SqlHelper. ExecuteDataset (DB. con, CommandType. Text, sequal). Tables [0];
// Initialize the paging data source instance
PagedDataSource PPS = new PagedDataSource ();
// Set the total number of rows
AspNetPager1.RecordCount = dt. Rows. Count;
// Set the paging Data Source
PPS. DataSource = dt. DefaultView;
// Set the current page
PPS. CurrentPageIndex = AspNetPager1.CurrentPageIndex-1;
// Set the number of pages displayed on each page
PPS. PageSize = AspNetPager1.PageSize;
// Enable Paging
PPS. AllowPaging = true;
// Set the data source of the GridView as a paging Data Source
GridView1.DataSource = pds;
// Bind the GridView
GridView1.DataBind ();
}

Protected void AspNetPager1_PageChanged (object sender, EventArgs e)
{
// Call the BIND page and the GridView
BindGridView ();
}
}
}

CSS style
. Anpager
{
Font: 11px Arial, Helvetica, sans-serif;
Padding: 10px 20px 10px 0;
Margin: 0px;
}
. Anpager
{
Padding: 1px 6px;
Border: solid 1px # ddd;
Background: # fff;
Text-decoration: none;
Margin-right: 2px
}
. Anpager a: visited
{
Padding: 1px 6px;
Border: solid 1px # ddd;
Background: # fff;
Text-decoration: none;
}
. Anpager. Cardiopulmonary Bypass
{
Padding: 1px 6px;
Font-weight: bold;
Font-size: 13px;
Border: none
}
. Anpager a: hover
{
Color: # fff;
Background: # ffa501;
Border-color: # ffa501;
Text-decoration: none;
}

/* AspNetPager1 attribute setting: CssClass = "anpager" CurrentPageButtonClass = "cardiopulmonary bypass "*/

Code in my life.
 

From ghypnus

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.