How to Use AspNetPager

Source: Internet
Author: User

1. Add references 2. Drag and Drop controls on the page 3. <% @ Register assembly = "AspNetPager" namespace = "Wuqi. webdiyer "tagprefix =" webdiyer "%> 4. set basic properties of the Control <webdiyer: aspNetPager ID = "AspNetPager1" runat = "server" FirstPageText = 'homepage' LastPageText = 'tail' margin = "10px" ShowPageIndexBox = "Always" CustomInfoHTML = "% RecordCount % Total, page % CurrentPageIndex %/Total % PageCount % PAGE "NextPageText =" next page "PrevPageText =" Previous Page "ShowCustomInfoSection =" Left "Sub MitButtonText = "Go" align = "page" align = "Go to" UrlPaging = "True" CustomInfoSectionWidth = "20%" CustomInfoTextAlign = "Center" onpagechanged = "aspnetpager#pagechanged"> </webdiyer: aspNetPager> 5. Background Code protected void Page_Load (object sender, EventArgs e) {string sqlStr = "select * from download where 1 = 1"; if (key. text! = "") {SqlStr + = "and title like '%" + key. text + "% 'order by id desc";} else {sqlStr + = "order by id desc";} string s = ConfigurationManager. connectionStrings ["siteconn"]. connectionString; // define the connection string SqlConnection conn = new SqlConnection (s); // create a database connection object, where s is the connection string conn. open (); // Open the connection to the database SqlCommand cmd = new SqlCommand (sqlStr, conn); AspNetPager1.AlwaysShow = true; AspNetPager1.PageSize = 15; AspNetPager1.RecordCount = (int) cmd. executeScalar (); conn. close (); bind ();} private void bind () {string sqlStr = "select * from download where 1 = 1"; if (key. text! = "") {SqlStr + = "and title like '%" + key. text + "% 'order by id desc";} else {sqlStr + = "order by id desc";} string s = ConfigurationManager. connectionStrings ["siteconn"]. connectionString; // define the connection string SqlConnection conn = new SqlConnection (s); // create a database connection object, where s is the connection string conn. open (); // Open the connection with the database DataSet myds = new DataSet (); SqlDataAdapter adapter = new SqlDataAdapter (sqlStr, conn); adapter. fill (myds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex-1), AspNetPager1.PageSize, "myds"); GridView1.DataSource = myds. tables ["myds"]; GridView1.DataBind ();} protected void aspnetpager?pagechanged (object sender, EventArgs e) {bind ();} 6. Add sequence number <asp: templateField HeaderText = "no."> <ItemTemplate> <% # (this. aspNetPager1.CurrentPageIndex-1) * this. aspNetPager1.PageSize + Container. dataItemIndex + 1%> </ItemTemplate> </asp: TemplateField>

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.