Manual paging using pagedatasource

Source: Internet
Author: User

 Using system; <br/> using system. data; <br/> using system. configuration; <br/> using system. collections; <br/> using system. web; <br/> using system. web. security; <br/> using system. web. ui; <br/> using system. web. UI. webcontrols; <br/> using system. web. UI. webcontrols. webparts; <br/> using system. web. UI. htmlcontrols; <br/> using system. data. sqlclient; <br/> Public partial class page: system. web. UI. page <br/> {<B R/> protected void page_load (Object sender, eventargs e) <br/>{< br/> If (! Page. ispostback) <br/>{< br/> BIND (); <br/>}< br/> int pagecount; // total number of pages <br/> int currentpage = 1; // defines the current page <br/> void BIND () <br/>{</P> <p> sqlconnection conn = new sqlconnection ("Server = .; database = pubs; uid = sa; Pwd = 123; "); <br/> string sqlstr =" select * from authors "; <br/> sqldataadapter SDA = new sqldataadapter (sqlstr, Conn); <br/> dataset DS = new dataset (); <br/> SDA. fill (DS, "pro"); <br/> // Create a data source <br/> pageddatasource PSP = new pageddatasource (); <br/> tp.dita. datasource = Ds. tables ["pro"]. defaultview; <br/> // allow pagination <br/> PPS. allowpaging = true; <br/> // set the number of records displayed on each page <br/> PPS. pagesize = int. parse (this. dropdownlist1.selecteditem. value); <br/> // obtain the total number of pages <br/> pagecount = PDS. pagecount; <br/> This. label1.text = pagecount. tostring (); <br/> PSP. currentpageindex = currentPage-1; <br/> // current page <br/> T His. label2.text = convert. tostring (currentpage); </P> <p> // data binding <br/> This. gridview1.datasource = PPS; <br/> This. gridview1.databind (); <br/> This. datalist1.datasource = PPS; <br/> This. datalist1.databind (); <br/> This. repeater1.datasource = PPS; <br/> This. repeater1.databind (); <br/>}< br/> protected void dropdownlistincluselectedindexchanged (Object sender, eventargs e) <br/>{< br/> BIND (); <br/>} <Br/> /// <summary> <br/> // page 1 <br/> /// </Summary> <br/> // <Param name = "sender"> </param> <br/> // <Param name = "E"> </param> <br/> protected void button#click (Object sender, eventargs e) <br/> {// if the current page is not the first page <br/> If (this. label2.text = "1") <br/>{</P> <p >}< br/> else <br/>{< br/> currentpage = 1; <br/> BIND (); <br/>}< br/> /// <summary> <br/> // next page <br/> /// </Summary> <br/> /// <Param name = "sender"> </param> <br/> // <Param name = "E"> </param> <br/> protected void button2_click (Object sender, eventargs e) <br/> {// if the current page is not the last page <br/> If (this. label1.text = This. label2.text) <br/>{< br/>}< br/> else <br/>{< br/> currentpage = int. parse (this. label2.text) + 1; <br/> This. label2.text = currentpage. tostring (); <br/> BIND (); <br/>}< br/> /// <summary> <br/> // previous Page <br/> /// </Summary> <br/> // <Param name = "sender"> </param> <br/> // <Param name = "E"> </param> <br/> protected void button3_click (Object sender, eventargs e) <br/> {// if the current page is not the first page <br/> If (this. label2.text! = "1") <br/>{< br/> currentpage = int. parse (this. label2.text)-1; <br/> This. label2.text = currentpage. tostring (); <br/> BIND (); <br/>}< br/> // <summary> <br/> // last page <br/> // </Summary> <br/> // <Param name = "sender"> </param> <br/> // <Param name = "E"> </param> <br/> protected void button4_click (Object sender, eventargs e) <br/> {// if the current page is not the last page <br/> If (this. label1.text! = This. label2.text) <br/>{< br/> This. label2.text = This. label1.text; <br/> currentpage = int. parse (this. label2.text); <br/> BIND (); <br/>}< br/> // page Jump <br/> protected void button5_click (Object sender, eventargs e) <br/>{< br/> currentpage = convert. toint32 (this. textbox1.text); <br/> BIND (); <br/>}< br/>

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.