Using system; Using system. Web. UI; Using system. Web. UI. webcontrols; Using system. componentmodel;Namespace pageinfocontrol { /// <Summary> /// Summary of webcustomcontrol1. /// </Summary> [Defaultproperty ("totalrecord "), Toolboxdata ("<{0}: pageinfo runat = Server> </{0}: pageinfo>")] Public class pageinfo: system. Web. UI. webcontrols. webcontrol, ipostbackeventhandler { # Region Construct Method /// <Summary> /// Constructor /// </Summary> Public pageinfo (): Base (htmltextwritertag. Div) { } # Endregion # Region variables and constants
Public event eventhandler changepageclick; Private string _ barbackgroundcolor = "# f1f1f1 "; Private string _ barlinkcolor = "Navy "; Private string _ barcurrentcolor = "# eeeeee "; Private int _ totalrecord = 0; Private int _ totalpage = 0; Private int _ pagesize = 0; Private int _ currentpageindex = 1; Private int _ itemsize = 10; # Endregion # Region Properties [ Description ("Paging background color "), Bindable (true ), Category ("appearance "), Defaultvalue ("# f1f1f1 ") ] Public String barbackgroundcolor { Get {return _ barbackgroundcolor ;} Set {_ barbackgroundcolor = value ;} } [ Description ("pagination strip link digit color "), Bindable (true ), Category ("appearance "), Defaultvalue ("Navy ") ] Public String barlinkcolor { Get {return _ barlinkcolor ;} Set {_ barlinkcolor = value ;} } [ Description ("number color of the current page of the pagination bar "), Bindable (true ), Category ("appearance "), Defaultvalue ("# eeeeee ") ] Public String barcurrentcolor { Get {return _ barcurrentcolor ;} Set {_ barcurrentcolor = value ;} } [ Description ("Total number of records "), Bindable (false ), Category ("behavior "), Defaultvalue (0) ] Public int totalrecord { Get {return _ totalrecord ;} Set { Foreach (char C in system. Convert. tostring (value )) { If (! Char. isnumber (c )) { _ Totalrecord = 0; Break; } } _ Totalrecord = value; } } [ Description ("number of records displayed per page "), Bindable (true ), Category ("behavior "), Defaultvalue (0) ] Public int pagesize { Get {return _ pagesize ;} Set { Foreach (char C in system. Convert. tostring (value )) { If (! Char. isnumber (c )) { _ Pagesize = 0; Break; } } _ Pagesize = value; } } [ Description ("Total pages "), Bindable (true ), Category ("behavior "), Defaultvalue (0) ] Public int totalpage { Get {return _ totalpage ;} } [ Description ("digital type "), Bindable (true ), Category ("behavior "), Defaultvalue (10) ] Public int itemsize { Get {return _ itemsize ;} Set { Foreach (char C in system. Convert. tostring (value )) { If (! Char. isnumber (c )) { _ Itemsize = 10; Break; } } _ Itemsize = value; } } [ Description ("Current page value "), Bindable (true ), Category ("behavior "), Defaultvalue (1) ] Public int currentpageindex { Get {return _ currentpageindex ;} Set {_ currentpageindex = value ;} } # Endregion // Define the DIV Style Protected override void addattributestorender (htmltextwriter writer) { Writer. addstyleattribute ("white-space", "nowrap "); Writer. addstyleattribute ("padding-top", "2px "); Writer. addstyleattribute ("padding-bottom", "2px "); Writer. addstyleattribute ("width", width. tostring ()); Writer. addstyleattribute ("height", height. tostring ()); Base. addattributestorender (writer ); } Protected virtual void onpagechangeclick (eventargs E) { If (changepageclick! = NULL) { Changepageclick (this, e ); } } Public void raisepostbackevent (string eventargument) { Int pageindex = int. parse (eventargument ); This. _ currentpageindex = pageindex; Onpagechangeclick (New eventargs ()); } /// <Summary> /// Present the control to the specified output parameter. /// </Summary> /// <Param name = "output"> HTML writer to be written </param> Protected override void rendercontents (htmltextwriter output) { This. _ totalpage = (this. totalrecord/pagesize) * This. pagesize = This. totalrecord )? (This. totalrecord/This. pagesize) :( (this. totalrecord/This. pagesize) + 1 ); Int beginrecord = (this. currentpageindex-1) * This. pagesize + 1; Int endrecord = This. currentpageindex * This. pagesize; Endrecord = (endrecord> This. totalrecord )? This. totalrecord: endrecord; String pageinfo = "[total <font color = # cc0000>" + this. totalpage. tostring () + "</font> page/current <font color = # cc0000>" + this. currentpageindex. tostring () + "</font> page <font color = # cc0000>" + totalrecord. tostring () + "</font> records, current number of records <font color = # cc0000>" + beginrecord. tostring () + "</font> to <font color = # cc0000>" + endrecord. tostring () + "</font>]"; String pageliststr = ""; String pageindexcolor = "#0000c0 "; Int singlenumber = This. totalpage-(totalpage/itemsize) * itemsize; // obtain the ending number after the page (for example, if the total number of 58 pages is displayed as 10 pages, the ending number is 8) Int intpageformax = (this. currentpageindex-1)/itemsize; Int MININT = (1 + itemsize * intpageformax ); Int maxint = (intpageformax + 1) * itemsize)> totalpage? Totalpage :( (intpageformax + 1) * itemsize ); If (this. totalrecord = 0 | this. totalpage = 0) { Pageliststr = "<font color =" + pageindexcolor + "> 0 </font> "; Pageliststr = pageliststr + "[total <font color = # cc0000> 0 </font> pages/current <font color = # cc0000> 0 </font> pages <font color = # cc0000> 0 </font> records, number of current records <font color = # cc0000> 0 </font> to <font color = # cc0000> 0 </font>] "; Output. Write (pageliststr ); } Else { If (this. totalpage <= This. itemsize) { For (INT I = 1; I <= totalpage; I ++) { Pageindexcolor = currentpageindex = I? "# Cc0000": "#0000c0 "; If (currentpageindex = I) Pageliststr = pageliststr + "<a Title = 'current: Page 'href =' # 'id =/" "+ this. uniqueid + "/"> <font color = "+ pageindexcolor +"> "+ I. tostring () + "</font> </a> "; Else Pageliststr = pageliststr + "<a Title = 'click to go To the'" + I + "" Page 'id =/"" + this. uniqueid + "/" href =/"javascript:" + Page. getpostbackeventreference (this, I. tostring () + "/"> <font color = "+ pageindexcolor +"> "+ I. tostring () + "</font> </a> "; } Pageliststr = ""? "<Font color =" + pageindexcolor + "> 0 </font>": pageliststr; Pageliststr = pageliststr + "" + pageinfo; Output. Write (pageliststr ); } Else { For (INT I = MININT; I <= maxint; I ++) { Pageindexcolor = currentpageindex = I? "# Cc0000": "#0000c0 "; If (currentpageindex = I) Pageliststr = pageliststr + "<a Title = 'current: Page 'href =' # 'id =/" "+ this. uniqueid + "/"> <font color = "+ pageindexcolor +"> "+ I. tostring () + "</font> </a> "; Else Pageliststr = pageliststr + "<a Title = 'click to go To the'" + I + "" Page 'id =/"" + this. uniqueid + "/" href =/"javascript:" + Page. getpostbackeventreference (this, I. tostring () + "/"> <font color = "+ pageindexcolor +"> "+ I. tostring () + "</font> </a> "; } // When the current page number is smaller than itemsize and the total page number is greater than itemsize If (currentpageindex <= itemsize & totalpage> itemsize) { Pageliststr = pageliststr + "<a id =/" "+ this. uniqueid + "/" Title = 'click to go to the "" + system. convert. tostring (itemsize + 1) + "" Page 'href =/"javascript:" + Page. getpostbackeventreference (this, system. convert. tostring (itemsize + 1) + "/" >></A> "; } // When the current page number is greater than itemsize and the total page number minus the current page number is greater than or equal to the last page number If (this. currentpageindex> itemsize & (totalpage-This. currentpageindex)> = singlenumber) { Int multiminpageindex = (intpageformax * itemsize ); Int multimaxpageindex = (intpageformax + 1) * itemsize) + 1; Pageliststr = "<a id =/" "+ this. uniqueid + "/" Title = 'click To Go To The' href =/"javascript:" + Page. getpostbackeventreference (this, multiminpageindex. tostring () + "/"> </a> "+ pageliststr. trim () + "<a id =/" "+ this. uniqueid + "/" Title = 'click To Go To The' href =/"javascript:" + Page. getpostbackeventreference (this, multimaxpageindex. tostring () + "/" >></A> "; } // When the current page number is greater than itemsize and the total page number minus the current page number is greater than or equal to the last page number If (currentpageindex> 10 & (totalpage-currentpageindex) <singlenumber) { Int multiminpageindex = (intpageformax * itemsize ); Pageliststr = "<a id =/" "+ this. uniqueid + "/" Title = 'click To Go To The' href =/"javascript:" + Page. getpostbackeventreference (this, multiminpageindex. tostring () + "/"> </a> "+ pageliststr. trim (); } Pageliststr = ""? "<Font color =" + pageindexcolor + "> 0 </font>": pageliststr; Pageliststr = pageliststr + "" + pageinfo; Output. Write (pageliststr ); } } Base. rendercontents (output ); } } } |