A total of three parts:. VB, Builder and Design
Imports system.componentmodel
Imports System.Web.ui.htmlControls
Imports System.Web.ui
Imports System.Web.ui.WebControls
Imports system.data
Imports system.data.OracleClient
Parsechildren (false), Persistchildren (false), _ Designer (Gettype (ChangePageDesigner), _ ToolboxData ("<{0}: changepage runat = server> {0}: changePage>")> Public class changepage Inherits System.Web.ui.WebControls.Panel Implements inamingcontainer Private Withevents TxtPage As NewTextBox Private Withevents BTNFirst As NewButton Private Withevents BTNNext As NewButton Private Withevents bstnprevious as newbutton Private Withevents btnlast as newbutton Private withevents btngo as newbutton Private Withevents LBLNOWPAGE As NewLabel Private Withevents LBLallPage As NewLabel Private Withevents LBLALLITEMS AS NEWLABEL Private Withevents LBLPAGE AS NewLabel Private HTMLTabel as Table Private HTMLROW AS TABLEROW Private iscreated as boolean Private MDataGrid As String Public Event PageIndexchange As EventHandler Public Sub New () End Sub #Region "プ プ パティ" NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("検 検 ボ ン ン")> _ Public Readonly Property PageTextBox () AS NewTextBox Get Me.ensureChildControls () Return TxtPage END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("First Page")> _Public Readonly Property FirstpageButton () AS NewButton Get Me.ensureChildControls () Return btnfirst END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Add Ido")> _ Public Readonly Property NextPageButton () AS NewButton Get Me.ensureChildControls () Return btnnext END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Previous Page ボ ン")> _ Public Readonly Property PrepageButton () As NewButton Get Me.ensureChildControls () Return bstnprevious END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Last page ボ タ ン")> _ Public Readonly Property LastPageButton () AS NewButton Get Me.ensureChildControls () Return btnlast END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Migrating ボ ン ン")> _ Public Readonly Property ChangeButton () As NewButton Get Me.ensureChildControls () Return BTNGO END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INnerProperty), _Category ("ChildControl"), Description ("Now ベ ベ")> _ Public Readonly Property NowpageLabel () AS NewLabel Get Me.ensureChildControls () Return LBLNOWPAGE END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Total Page ベ ベ")> _ Public Readonly Property AllpageLabel () AS NewLabel Get Me.ensureChildControls () Return LBLallPage END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Total Project ベ ベ ベ")> _ Public Readonly Property AlliteMslabel () AS NewLabel Get Me.ensureChildControls () Return LBLALLITEMS END GET End Property NotifyParentProperty (True), PersistenceMode (PersistenceMode.INNerProperty), _ Category ("ChildControl"), Description ("Page ベ ベ ベ")> _ Public Readonly Property Pagelabel () AS NewLabel Get Me.ensureChildControls () Return LBLPAGE END GET End Property Public property DataGrid () AS String Get Return MDataGrid END GET Set (byval value as string) MDataGrid = Value End set End Property #End region Protected Overrides Sub CreateChildControls () HTMLTabel = New Table HTMLROW = New Tables IF txtpage is nothing then Iscreated = falsetxtPage = new new deskTextBox TXTPAGE.ID = mybase.id & "_pagetextbox" Else Iscreated = true END IF IF btnfirst is nothing then Iscreated = false btnfirst = new new newbutton Btnfirst.id = mybase.id & "_firstpagebutton" Else Iscreated = true END IF IF btnnext is nothing then Iscreated = false btnnext = new newbutton btnnext.id = mybase.id & "_nextpagebutton" Else Iscreated = true END IF IF btnprevious is nothing then Iscreated = false Btnprevious = new newbutton Btnprevious.id = mybase.id & "_prepagebutton" Else Iscreated = true END IF IF btnlast is nothing then Iscreated = false btnlast = new new new Btnlast.id = mybase.id & "_lastpagebutton" Else Iscreated = true END IF IF btngo is nothing then Iscreated = false Btngo = new newbutton btngo.id = mybase.id & "_changepagebutton" Else Iscreated = true END IF If lblnowpage is nothing then Iscreated = false LBLNOWPAGE = New NewLabel LBLNOWPAGE.ID = mybase.id & "_nowpagelabel" Else Iscreated = true END IF If lblalpage is nothing then Iscreated = false LBLallPage = New NewLabel LBLallPage.ID = mybase.id & "_allpagelabel" Else Iscreated = true END IF If lballitems is nothing then Iscreated = false LBLALLITEMS = New NewLabel LBLALLITEMS.ID = MyBase.ID & "_allItemslabel" Else Iscreated = true END IF If lblpage is nothing then Iscreated = false LBLPAGE = New New NewLabel LBLPAGE.ID = mybase.id & "_pagelabel" Else Iscreated = true End ifmybase.createchildControls () If iscreated = false kil LBLPage.Text = "Page へ" btnfirst.text = "First Page" btnprevious.text = "Previous" btnnext.text = "Type Page" btnlast.text = "Last" btngo.text = "Migration" LBLNOWPAGE.TEXT = "0" LBLallPage.Text = "/ 0 pages" LBLALLITEMS.TEXT = "whole て: 0 pieces" TXTPAGE.WIDTH = Unit.pixel (40) END IF Htmltabel.cellpadding = 0 HTMLTabel.cellspacing = 0 HTMLTabel.Rows.Add (HTMLROW) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (0). Horizontalalign = horizontalalign.Left HTMLROW.CELLS (0) .controls.add (btnfirst) HTMLROW.CELLS (0) .controls.add (btnprevious) HTMLROW.CELLS (0) .controls.add (btnnext) HTMLROW.CELLS (0) .controls.add (btnlast) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (1) .horizontalalign = horizontalalign.Left HTMLROW.CELLS (1) .controls.add (txtpage) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (2) .horizontalalign = horizontalalign.Left HTMLROW.CELLS (2) .controls.add (lblpage) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (3) .horizontalalign = horizontalalign.left HTMLROW.CELLS (3) .controls.add (btngo) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (4) .hizontalalign = horizontalalign.left HTMLROW.CELLS (4) .controls.add (lblnowpage) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (5) .horizontalalign = horizontalalign.Left HTMLROW.CELLS (5) .controls.add (lblallpage) Htmlrow.cells.Add (New TableCell) Htmlrow.cells (6) .horizontalalign = Horizontalalign.Left Htmlrow.cells (6) .controls.add (lblallitems) Mybase.controls.add (HTMLTabel) End Sub Protected Overrides Sub Render (Byval Output As System.Web.ui.htmlTextWriter) Mybase.ensurechildControls () RenderChildren (Output) End Sub Protected Overrides Sub AddparsedSubObject (Byval Obj As Object) Dim btnidname as array Dim lblidname as array If TypeOf Obj Is NewTextBox Then TXTPAGE = OBJ END IF IF TypeOf Obj Is Newbutton Then BtnidName = Split (ctype (obj, newbutton) .id.toString, "_") SELECT CASE BTNIDNAME (1) .tostring Case "firstpagebutton" Me.btnfirst = OBJ Case "NextPageButton" Me.btnnext = OBJ Case "prepagebutton" Me.btnprevious = OBJ Case "lastpagebutton" Me.btnlast = OBJ Case "ChangePageButton" Me.btngo = OBJ End SELECT END IF If Typeof Obj Is NewLabel Then LBLidName = Split (ctype (obj, newlabel) .id.toString, "_") SELECT CASE LBLIDNAME (1) .tostring Case "nowpagelabel" Me.lblnowpage = OBJ Case "AllpageLabel" Me.lblalpage = OBJ Case "Allitemslabel" Me.lbLallItems = OBJ Case "Pagelabel" Me.lblpage = OBJ End SELECT END IF End Sub Private sub btnfirst_click (Byval e as system.eventargs) Handles btnfirst.click Mybase.ensurechildControls () If not page.FindControl (DataGrid) Is Nothing Then Ctype (page.FindControl (DataGrid), DataGrid) .currentpageIndex = 0 TXTPAGE.TEXT = "" " Raiseevent PageIndexchange (ME, E) Call newPageDatabaseD () Else Throw New Exception (DataGrid & "し し 当 当 当 当") END IF End Sub Private sub btnlast_click (Byval e as system.eventargs) Handles btnlast.click DIM PageCount as integer Mybase.ensurechildControls () If not page.FindControl (DataGrid) Is Nothing Then PageCount = ctype (page.FindControl (DataGrid), DataGrid) .pagecount Ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex = _Math.max (PageCount - 1, 0) TXTPAGE.TEXT = "" " Raiseevent PageIndexchange (ME, E) Call newPageDatabaseD () Else Throw New Exception (DataGrid & "し し 当 当 当 当") END IF End Sub Private sub btnnext_click (Byval e as system.eventargs) Handles btnnext.click DIM CurrentPageIndex as in Integer DIM PageCount as integer Mybase.ensurechildControls () If not page.FindControl (DataGrid) Is Nothing Then PageCount = ctype (page.FindControl (DataGrid), DataGrid) .pagecount CurrentPageIndex = ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex Ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex = _ Math.min (CurrentPageIndex 1, PageCount - 1) TXTPAGE.TEXT = "" " Raiseevent PageIndexchange (ME, E) Call newPageDatabaseD () Else Throw New Exception (DataGrid & "し し 当 当 当 当") END IF End Sub Private sub btnprevious_click (Byval e as system.eventargs) Handles btnprevious.click DIM CurrentPageIndex as in Integer Mybase.ensurechildControls () If not page.FindControl (DataGrid) Is Nothing Then CurrentPageIndex = ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex Ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex = _ Math.max (CurrentPageIndex - 1, 0) TXTPAGE.TEXT = "" " Raiseevent PageIndexchange (ME, E) Call newPageDatabaseD () Else Throw New Exception (DataGrid & "し し 当 当 当 当") END IF End Sub Public Sub NewPageDataBind () Dim Recordcount As Integer DIM PageCount as integer DIM PagedGDsize As INTEGER DIM CurrentPageIndex as in Integer CurrentPageIndex = ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndexPagedGDsize = ctype (Page.FindControl (DataGrid), DataGrid) .pageSize PageCount = ctype (page.FindControl (DataGrid), DataGrid) .pagecount IF (ctype (page.findcontrol (datagrid), datagrid) .datasource is nothingin SetButtonState (0, CurrentPageIndex) EXIT SUB END IF IF (ctype (page.findcontrol), DataGrid) .DataSource.gettype (). Tostring (). _ TOLOWER () = "system.data.dataable") THEN Recordcount = ctype (page.FindControl (DataGrid), DataGrid) .datasource.Rows.count Elseif (CType (PagePe). DataSource.getType (). Tostring (). _ TOLOWER () = "system.data.dataview") THEN Recordcount = ctype (page.FindControl (DataGrid), DataGrid) .DataSource.count Elseif (CType (PagePe). DataSource.getType (). Tostring (). _ TOLOWER () = "system.data.dataset") THEN Recordcount = ctype (page.FindControl (DataGrid), DataGrid) .DataSource.tables (0). _ Rows.count END IF IF PageCount.toString = 0 THEN LBLNOWPAGE.TEXT = 0 Else LBLNOWPAGE.TEXT = _ (Ctype (page.findcontrol (datagrid), DataGrid) .CurrentPageIndex 1) .tostring () END IF LBLallPage.Text = "/" & pagecount.tostring () & "page" LBLALLITEMS.TEXT = "全::" & RecordCount.toString () & "Pie" SetButtonState (PageCount, CurrentPageIndex) End Sub Public Sub setButtonState (Byval CurrentPageIndex as integer): PUBLIC SUNT AS INTEGER btnfirst.enabled = (0 Btnprevious.enabled = (0 Btnnext.enabled = (CurrentPageIndex Btnlast.enabled = (CurrentPageIndex TXTPAGE.ENABLED = (1 End Sub Private sub btngo_click (Byval e as system.eventargs) Handles btngo.click DIM PageCount as integer If not page.FindControl (DataGrid) Is Nothing Then PageCount = ctype (page.FindControl (DataGrid), DataGrid) .pagecount Else Throw New Exception (DataGrid & "し し 当 当 当 当") EXIT SUB END IF IF txtpage.text.to TXTPAGE.TEXT.TOString.Equals ("") THEN EXIT SUB Else IF PageCount TXTPAGE.TEXT = "" " EXIT SUB Else IF Math.min (PageCount - 1, CINT (TXTPAGE.TEXT) - 1) <0 THEN TXTPAGE.TEXT = "" " EXIT SUB END IF Ctype (page.FindControl (DataGrid), DataGrid) .CurrentPageIndex = _ Math.min (PageCount - 1, CINT (TXTPAGE.TEXT) - 1) TXTPAGE.TEXT = "" " Raiseevent PageIndexchange (ME, E) Call newPageDatabaseD () END IF END IF End Sub PRIVATE SUB CHANGEPAGE_LOAD (Byval e as system.eventargs) Handles mybase.load Mybase.ensurechildControls () IF dataGrid is nothing then Throw new Exception ("necessary DataGrid プ パティ が が れ い い") EXIT SUB END IF If not page.FindControl (DataGrid) Is Nothing Then Call newPageDatabaseD () Else Throw New Exception (DataGrid & "し し 当 当 当 当") END IF End Sub END CLASS Imports system.componentmodel Imports System.Web.ui Public Class ChangePageBuilder Inherits Controlbuilder Public overrides function getchildControlType (Byval Tagname As String, Byval Attributes As Idictionary) AS TYPE If Tagname.tolower (). Endswith ("NewTextBox") THEN Return GetType (NewTextBox) END IF IF tagname.tolower (). Endswith ("newbutton") Thenreturn GetType (NewButton) END IF If tagname.tolower (). Endswith ("NewLabel") THEN Return GetType (NewLabel) END IF Return Nothing END FUNCTION END CLASS Imports system.io Imports System.Web.ui Imports System.Web.ui.WebControls Imports system.web.ui.design Imports system.componentmodel Imports system.componentmodel.design Public Class ChangePageDesigner Inherits ControlDesigner Public overrides function getdesigntimehtml () AS STRING DIM STRWRITER AS STRINGWRITER DIM HTMLWRITER AS HTMLTEXTWRITER DIM Control As ChangePage Strwriter = New StringWriter HTMLWRITER = New HTMLTextWriter (Strwriter) Control = ctype (me.component, changepage) Mybase.getdesigntimehtml () IF not control.hascontrols kil Return getemptyDesigntimehtml () END IF Control.renderControl (HTMLWRITER) Return strwriter.tostring END FUNCTION Public overrides function getPersistinnerHtml () AS STRING DIM STRWRITER AS STRINGWRITER DIM HTMLWRITER AS HTMLTEXTWRITER DIM Control As ChangePage Strwriter = New StringWriter HTMLWRITER = New HTMLTextWriter (Strwriter) Control = ctype (me.component, changepage) Mybase.getpersistinnerhtml () HTMLWRITER.WRITE (ControlPersister.PersistControl (control.firstpagebutton)) HTMLWRITER.WRITE (ControlPersister.PersistControl (Control.PrepageButton)) HTMLWRITER.WRITE (ControlPersister.PersistControl (Control.NextPageButton)) HTMLWRITER.WRITE (ControlPersister.PersistControl (control.lastpagebutton)) HTMLWRITER.WRITE (ControlPersister.PersistControl (Control.PageTextBox)) HTMLWRITER.WRITE (ControlPersister.PersistControl (control.pagelabel)) HTMLWRITER.WRITE (Control.ChangePageButton) HTMLWRITER.WRITE (ControlPERSISTER.PERSISTCONTROL (Control.NowPageLabel) HTMLWRITER.WRITE (ControlPersister.PersistControl (Control.allpageLabel)) HTMLWRITER.WRITE (ControlPersister.PersistControl (Control.allItemslabel)) Return strwriter.tostring END FUNCTION END CLASS