Asp. NET paging components learning and using--using articles

Source: Internet
Author: User
Tags count tostring
asp.net| paging ASP. NET paging components learning and using--using articles



Hello everyone, this article is the last article "ASP." NET pagination component learning and using--teaching article.



In the ASP. NET pagination component learning and using--teaching article, we explained the entire creation process of the paging component, so in this article, we discuss how to use the component.



Follow these steps:

1. Create a Web application project.



2, add the components generated in the previous article to the Toolbox. If you do not know the procedure to add, please refer to the article ASP. NET component programming Step by step





3. In the Default Web Forms page, switch to HTML view and copy the following HTML code into the <form> tab.

<div align= "center" >

<center>

<table border= "0" cellpadding= "0" cellspacing= "0" width= "756" height= "" style= "font-size:12px" >

<tr>

&LT;TD width= "756" height= ">" Use instance of pagination control </td>

</tr>

<tr>

&LT;TD width= "756" height= "valign=" "Top" align= "center" runat= "server" id= "myhtml" ></td>

</tr>

<tr>

&LT;TD width= "756" height= ">"

</td>

</tr>

</table>

</center>

</div>



4, the HTML code generates a table of three rows, and from the Toolbox, drag the control to the third row of the table.



5. Add the following code in the private void Page_Load (object sender, System.EventArgs e) event handler:

int CP;

if (this. request.params["currentpage"] = = null)

{

CP = 1;

}

Else

{

CP = Convert.ToInt32 (this. request.params["CurrentPage"]);

}



SqlConnection con = new SqlConnection ("Server=accp-lzh;uid=sa;pwd=sasa;database=northwind");

SqlCommand cmd = new SqlCommand ("SELECT * from [Order Details]", con);

SqlDataAdapter adapter = new SqlDataAdapter ();

Adapter. SelectCommand = cmd;

DataSet ds = new DataSet ();

Con. Open ();

Adapter. Fill (ds, "table");

Con. Close ();



DataTable dt = new DataTable ();

DT = ds. tables["Table"];

The following sets the control parameters

This. Lzhpages1.allcount = dt. rows.count;//Total Record Bar number

This. Lzhpages1.currentpage = cp;//The current page, read from the URL

This. Lzhpages1.showpages = number of 10;//navigation numbers

This. Lzhpages1.count = 10;//number of record bars displayed per page



StringBuilder sql = new StringBuilder ();

The following three strings are eventually combined into a complete table <table>

String htmlheader = "";//<table> label

String htmlBody = "";//There are a number of <tr> tags in the middle.

String htmlfoot = "";//</table> label



Sql. AppendFormat ("Select top {0} * from [order Details] where 1=1 and OrderID" (select top {1}) OrderID from [Order Detai LS] where 1=1 ORDER by OrderID Desc) ", and" by OrderID Desc. Lzhpages1.count,this. Lzhpages1.currentpage * this. Lzhpages1.count);

SqlCommand cmd1 = new SqlCommand (SQL. ToString (), con);

Adapter. SelectCommand = CMD1;

Con. Open ();

Adapter. Fill (ds, "Table1");

Con. Close ();



dt= ds. tables["Table1"];

HTMLheader = "<table style= ' font-size:12px ' border= ' 1 ' cellpadding= ' 0 ' cellspacing= ' 0 ' width= ' 100% ' bordercolor= '" 008000 ' bordercolorlight= ' #008000 ' bordercolordark= ' #FFFFFF ' >\n ';



for (int i = 0;i < dt. Rows.Count i + +)

{

HtmlBody = HtmlBody + String.Format ("<tr>\n<td width= ' 12% ' >{0}</td>\n<td width= ' 43% '" >{1}< /TD&GT;\N&LT;TD width= ' 24% ' >{2}</td><td width= ' 21% ' >{3}</td>\n</tr>\n ', dt. Rows[i][0]. ToString (), dt. ROWS[I][1]. ToString (), dt. ROWS[I][2]. ToString (), dt. ROWS[I][3]. ToString ());

}

Htmlfoot = "</table>\n";



this.myHtml.InnerHtml = HTMLheader + htmlBody + htmlfoot;



6, SQL. AppendFormat ("Select top {0} * from [order Details] where 1=1 and OrderID" (select top {1}) OrderID from [Order Detai LS] where 1=1 ORDER by OrderID Desc) ", and" by OrderID Desc. Lzhpages1.count,this. Lzhpages1.currentpage * this. LZHPAGES1.COUNT); The SQL statements in this statement are used for paging, our controls are used only to control the page, and the data is read through SQL statements or stored procedures.



7, the result chart:



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.