Repeater page (pageddatasource)

Source: Internet
Author: User
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! 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"> </Html>

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; public partial class _ default: system. web. UI. page {sqlconnection conn = new sqlconnection ("Server = .; database = Master; uid = sa; Pwd = sa "); protected Vo Id page_load (Object sender, eventargs e) {If (! Ispostback) {This. labpage. TEXT = "1"; this. contrlrepeater () ;}} // obtain the number of characters in the private string cuts (string AA, int bb) {If (AA. length <= bb) {return AA;} else {return AA. substring (0, BB) ;}} private dataset returnds (string sqlstr) {dataset DS = new dataset (); try {Conn. open (); sqlcommand comm = new sqlcommand (sqlstr, Conn); Comm. commandtimeout = 20; sqldataadapter SDA = new sqldataadapter (Comm); SDA. fill (DS, "temptable"); Conn. close (); Return Ds;} catch {return NULL;} private bool exectuesql (string sqlstr) {try {Conn. open (); sqlcommand comm = new sqlcommand (sqlstr, Conn); int temp = comm. executenonquery (); Conn. close (); If (temp> 0) return true; else return false;} catch {return false;} // repeater pagination control display method public void contrlrepeater () {dataset Ss = new dataset (); SS = returnds ("select top 200 * from test"); pageddatasource PDS = new pageddatasource (); Pam. datasource = ss. tables ["temptable"]. defaultview; Pam. allowpaging = true; Pam. pagesize = 10; Pam. currentpageindex = convert. toint32 (this. labpage. text)-1; rptshowlink. datasource = PPS; labcountpage. TEXT = PPS. pagecount. tostring (); labpage. TEXT = (pps. currentpageindex + 1 ). tostring (); this. lbtnpritpage. enabled = true; this. lbtnfirstpage. enabled = true; this. lbtnnextpage. enabled = true; this. lbtndownpage. enabled = true; If (PDS. currentpageindex <1) {This. lbtnpritpage. enabled = false; this. lbtnfirstpage. enabled = false;} If (PDS. currentpageindex = PDS. pagecount-1) {This. lbtnnextpage. enabled = false; this. lbtndownpage. enabled = false;} rptshowlink. databind ();} protected void lbtnpritpage_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (labpage. text)-1); this. contrlrepeater ();} protected void lbtnfirstpage_click (Object sender, eventargs e) {This. labpage. TEXT = "1"; this. contrlrepeater ();} protected void lbtndownpage_click (Object sender, eventargs e) {This. labpage. TEXT = This. labcountpage. text; this. contrlrepeater ();} protected void lbtnnextpage_click (Object sender, eventargs e) {This. labpage. TEXT = convert. tostring (convert. toint32 (labpage. text) + 1); this. contrlrepeater ();} // modify protected void btnupdate_click (Object sender, commandeventargs e) {int id = convert. toint32 (E. commandname);} // delete protected void btndelete_click (Object sender, commandeventargs e) {int id = convert. toint32 (E. commandname); string STR = "delete test where orderid =" + ID; If (exectuesql (STR) response. write ("<script language = 'javascript '> alert ('successful'); </SCRIPT>"); else {response. write (@ "<script language = 'javascript '> alert ('failed'); </SCRIPT> ");}}} /* If exists (select * From sysobjects where name = 'test') Drop table test go create table test (orderid int, mermerid varchar (12), employeeid varchar (12 ), orderdate varchar (12) insert into test values (1, '1', '1', '1'); insert into test values (2, '2 ', '2', '2'); insert into test values (3, '3', '3', '3'); insert into test values (4, '5 ', '51', '31'); insert into test values (5, '000000', '000000', 'sdfh1 '); select * from TES */

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.