分享
 
 
 

翻页的WEB控件

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

总共分三部分:。VB,Builder和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

<DefaultProperty("ChangePage"), ControlBuilderAttribute(GetType(ChangePageBuilder)), _

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 btnPrevious 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 "プロパティ"

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("検索ボタン")> _

Public ReadOnly Property PageTextBox() As newTextBox

Get

Me.EnsureChildControls()

Return txtPage

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("初頁ボタン")> _

Public ReadOnly Property FirstPageButton() As newButton

Get

Me.EnsureChildControls()

Return btnFirst

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("次頁ボタン")> _

Public ReadOnly Property NextPageButton() As newButton

Get

Me.EnsureChildControls()

Return btnNext

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("前頁ボタン")> _

Public ReadOnly Property PrePageButton() As newButton

Get

Me.EnsureChildControls()

Return btnPrevious

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("末頁ボタン")> _

Public ReadOnly Property LastPageButton() As newButton

Get

Me.EnsureChildControls()

Return btnLast

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("遷移ボタン")> _

Public ReadOnly Property ChangePageButton() As newButton

Get

Me.EnsureChildControls()

Return btnGo

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("現在の頁ラベル")> _

Public ReadOnly Property NowPageLabel() As newLabel

Get

Me.EnsureChildControls()

Return lblNowPage

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("合計頁ラベル")> _

Public ReadOnly Property AllPageLabel() As newLabel

Get

Me.EnsureChildControls()

Return lblAllPage

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("合計項目ラベル")> _

Public ReadOnly Property AllItemsLabel() As newLabel

Get

Me.EnsureChildControls()

Return lblAllItems

End Get

End Property

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _

NotifyParentProperty(True), PersistenceMode(PersistenceMode.InnerProperty), _

Category("ChildControl"), Description("頁ラベル")> _

Public ReadOnly Property PageLabel() As newLabel

Get

Me.EnsureChildControls()

Return lblPage

End Get

End Property

<Category("Behavior"), Description("データグリッド項目のコントロール"), DefaultValue("")> _

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 TableRow

If txtPage Is Nothing Then

isCreated = False

txtPage = New newTextBox

txtPage.ID = MyBase.ID & "_PageTextBox"

Else

isCreated = True

End If

If btnFirst Is Nothing Then

isCreated = False

btnFirst = 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 newButton

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 lblAllPage Is Nothing Then

isCreated = False

lblAllPage = New newLabel

lblAllPage.ID = MyBase.ID & "_AllPageLabel"

Else

isCreated = True

End If

If lblAllItems 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 newLabel

lblPage.ID = MyBase.ID & "_PageLabel"

Else

isCreated = True

End If

MyBase.CreateChildControls()

If isCreated = False Then

lblPage.Text = "頁へ"

btnFirst.Text = "初頁"

btnPrevious.Text = "前頁"

btnNext.Text = "次頁"

btnLast.Text = "末頁"

btnGo.Text = "遷移"

lblNowPage.Text = "0"

lblAllPage.Text = "/0頁"

lblAllItems.Text = " 全て:0件"

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).HorizontalAlign = 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.lblAllPage = obj

Case "AllItemsLabel"

Me.lblAllItems = obj

Case "PageLabel"

Me.lblPage = obj

End Select

End If

End Sub

Private Sub btnFirst_Click(ByVal sender As Object, 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 NewPageDataBind()

Else

Throw New Exception(DataGrid & "を探し当てていない")

End If

End Sub

Private Sub btnLast_Click(ByVal sender As Object, 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 NewPageDataBind()

Else

Throw New Exception(DataGrid & "を探し当てていない")

End If

End Sub

Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click

Dim currentPageIndex As 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 NewPageDataBind()

Else

Throw New Exception(DataGrid & "を探し当てていない")

End If

End Sub

Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click

Dim currentPageIndex As 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 NewPageDataBind()

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 Integer

CurrentPageIndex = CType(Page.FindControl(DataGrid), DataGrid).CurrentPageIndex

pageDgdSize = CType(Page.FindControl(DataGrid), DataGrid).PageSize

pageCount = CType(Page.FindControl(DataGrid), DataGrid).PageCount

If (CType(Page.FindControl(DataGrid), DataGrid).DataSource Is Nothing) Then

SetButtonState(0, CurrentPageIndex)

Exit Sub

End If

If (CType(Page.FindControl(DataGrid), DataGrid).DataSource.GetType().ToString(). _

ToLower() = "system.data.datatable") Then

recordCount = CType(Page.FindControl(DataGrid), DataGrid).DataSource.Rows.Count

ElseIf (CType(Page.FindControl(DataGrid), DataGrid).DataSource.GetType().ToString(). _

ToLower() = "system.data.dataview") Then

recordCount = CType(Page.FindControl(DataGrid), DataGrid).DataSource.Count

ElseIf (CType(Page.FindControl(DataGrid), DataGrid).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() & "頁"

lblAllItems.Text = " 全て:" & recordCount.ToString() & "件"

SetButtonState(pageCount, CurrentPageIndex)

End Sub

Public Sub SetButtonState(ByVal pageCount As Integer, ByVal CurrentPageIndex As Integer)

btnFirst.Enabled = (0 < CurrentPageIndex)

btnPrevious.Enabled = (0 < CurrentPageIndex)

btnNext.Enabled = (CurrentPageIndex < pageCount - 1)

btnLast.Enabled = (CurrentPageIndex < pageCount - 1)

btnGo.Enabled = (1 < pageCount)

txtPage.Enabled = (1 < pageCount)

End Sub

Private Sub btnGo_Click(ByVal sender As Object, 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.ToString.Equals("") Then

Exit Sub

Else

If PageCount < CInt(txtPage.Text) Then

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 NewPageDataBind()

End If

End If

End Sub

Private Sub ChangePage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

MyBase.EnsureChildControls()

If DataGrid Is Nothing Then

Throw New Exception("必要なDataGridプロパティが設定されていない")

Exit Sub

End If

If Not Page.FindControl(DataGrid) Is Nothing Then

Call NewPageDataBind()

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") Then

Return 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 Then

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(ControlPersister.PersistControl(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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有