(GO). NET implement Repeater control +aspnetpager control pagination

Source: Internet
Author: User

SqlConnection (. NET C #) connectivity and paging
The. NET Access data mechanism determines that accessing large amounts of data can cause client machines to consume a significant amount of resources, so it is necessary to page out data, develop tools vs.net+sqlserver, language C #

1. Add a reference

Introduce the Aspnetpager control into the project, adding references to the ASPX page, and adding the Aspnetpager DLL file to the Bin folder directory
Using System.Data.SqlClient;
Using Wuqi.webdiyer;

2. The foreground display page aspx

<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_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 ">

<title> Untitled Page </title>
<link href= "Stylesheet.css" rel= "StyleSheet" type= "Text/css"/>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:repeater id= "Repeater1" runat= "Server" >
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li><%# "Customer ID:" +eval ("CustomerID")%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <%# "Company Name:" +eval ("CompanyName")%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%# "contact Address: "+eval" ("Address")%></li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
<br/>
<webdiyer:aspnetpager id= "AspNetPager1" runat= "Server" firstpagetext= "lastpagetext=" "
Nextpagetext= "Next" onpagechanging= "aspnetpager1_pagechanging" cssclass= "pages" currentpagebuttonclass= "CPB" prevpagetext= "Prev" >
</webdiyer:AspNetPager>
</div>
</form>
</body>

3. Background Code Section Aspx.cs

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;
Using Wuqi.webdiyer;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Bindsql ();
}
}
private void Bindsql ()
{
SqlConnection con = new SqlConnection ("Data source=20090731-5465;initial catalog=northwind;integrated security=true") ;
Con. Open ();
SqlDataAdapter sqlda = new SqlDataAdapter ("Select * from Customers", con);
DataSet ds = new DataSet ();
Sqlda. Fill (DS);
PagedDataSource pdslist = new PagedDataSource ();
Pdslist.datasource = ds. Tables[0]. DefaultView;
pdslist.allowpaging = true;//Data source allows paging
Pdslist.pagesize = this. aspnetpager1.pagesize;//the paging size of the control
Pdslist.currentpageindex = this. aspnetpager1.currentpageindex-1;//Display the current page
setting controls
This. Aspnetpager1.recordcount = ds. Tables[0]. rows.count;//Total Records
This. Aspnetpager1.pagesize = 10;
This. Repeater1.datasource = pdslist;
This. Repeater1.databind ();

}
protected void Aspnetpager1_pagechanging (Object src, Pagechangingeventargs e)
{
Aspnetpager1.currentpageindex = E.newpageindex;
Bindsql ();
}
}

4.CSS File Style Sheet

Body {
}
. pages {color: #999;}
. pages a,. pages. CPB {text-decoration:none;float:left; padding:0 5px; border:1px solid #ddd; background: #ffff; margin: 0 2px; font-size:11px; Color: #000;}
. pages A:hover {background-color: #E61636; color: #fff; border:1px solid #E61636; text-decoration:none;}
. pages. CPB {font-weight:bold; color: #fff; background: #E61636; border:1px solid #E61636;}

(GO). NET implement Repeater control +aspnetpager control pagination

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.