ASP.net 2.0 自定义控件的开发之数据分页 第三章

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

控件的属性及事件定义

Private Shared ReadOnly EventibGotoPageClick As New Object()

Private Shared ReadOnly EventlbGotoPageClick As New Object()

Private Conn As SqlConnection

Private _StoredProcedureName As String

Private _ControlToDataBind As String

Private _GoToStyle As StyleGoTo = StyleGoTo.LinkButton

Private intPageCount As Int32 = 0

Private intRecordCount As Int32 = 0

Private intPageSize As Int32

Private _DefaultImageUrl As String

Private _HoverImageUrl As String

Private _PressedImageUrl As String

Private _controlToPaginat As Control

Private labPageInfo As Label

Private labPageInfoText_01 As Label

Private labPageInfoText_02 As Label

Private labPageInfoText_03 As Label

Private labPageInfoText_04 As Label

Private txtPageSize As TextBox

Private txtPageIndex As TextBox

Private ibGotoPage As ImageButton

Private lbGotoPage As LinkButton

Private lbFirstPage As LinkButton

Private lbPrevPage As LinkButton

Private lbNextPage As LinkButton

Private lbLastPage As LinkButton

属性定义#Region "属性定义"

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

< _

Bindable(True), _

Category("PageInfo"), _

DefaultValue(""), _

Description("设置页的信息(例如:当前 100 条记录...).") _

> _

Public Property PageInfoText()Property PageInfoText() As String

Get

EnsureChildControls()

Return labPageInfo.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

labPageInfo.Text = value

End Set

End Property

< _

Bindable(True), _

Category("PageInfo"), _

DefaultValue(""), _

Description("设置显示 每页 字符.") _

> _

Public Property PageInfoText_01()Property PageInfoText_01() As String

Get

EnsureChildControls()

Return labPageInfoText_01.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

labPageInfoText_01.Text = value

End Set

End Property

< _

Bindable(True), _

Category("PageInfo"), _

DefaultValue(""), _

Description("设置显示 条记录 字符.") _

> _

Public Property PageInfoText_02()Property PageInfoText_02() As String

Get

EnsureChildControls()

Return labPageInfoText_02.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

labPageInfoText_02.Text = value

End Set

End Property

< _

Bindable(True), _

Category("PageInfo"), _

DefaultValue(""), _

Description("设置显示 转到 字符.") _

> _

Public Property PageInfoText_03()Property PageInfoText_03() As String

Get

EnsureChildControls()

Return labPageInfoText_03.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

labPageInfoText_03.Text = value

End Set

End Property

< _

Bindable(True), _

Category("PageInfo"), _

DefaultValue(""), _

Description("设置显示 页 字符.") _

> _

Public Property PageInfoText_04()Property PageInfoText_04() As String

Get

EnsureChildControls()

Return labPageInfoText_04.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

labPageInfoText_04.Text = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("页大小 Textbox 边框的宽度.") _

> _

Public Property TextboxBorderWidth()Property TextboxBorderWidth() As Unit

Get

EnsureChildControls()

Return txtPageSize.BorderWidth

End Get

Set(ByVal value As Unit)

EnsureChildControls()

txtPageSize.BorderWidth = value

txtPageIndex.BorderWidth = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("页大小 Textbox 边框的颜色.") _

> _

Public Property TextboxBorderColor()Property TextboxBorderColor() As System.Drawing.Color

Get

EnsureChildControls()

Return txtPageSize.BorderColor

End Get

Set(ByVal value As System.Drawing.Color)

EnsureChildControls()

txtPageSize.BorderColor = value

txtPageIndex.BorderColor = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("页大小 Textbox 的SkinID.") _

> _

Public Property TextboxSkinID()Property TextboxSkinID() As String

Get

EnsureChildControls()

Return txtPageSize.SkinID

End Get

Set(ByVal value As String)

EnsureChildControls()

txtPageSize.SkinID = value

txtPageIndex.SkinID = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("设置转到的的风格.") _

> _

Public Property GoToStyle()Property GoToStyle() As StyleGoTo

Get

EnsureChildControls()

Return Me._GoToStyle

End Get

Set(ByVal value As StyleGoTo)

EnsureChildControls()

Me._GoToStyle = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("设置转到的按钮默认图片.") _

> _

Public Property DefaultImageUrl()Property DefaultImageUrl() As String

Get

EnsureChildControls()

Return ibGotoPage.ImageUrl

End Get

Set(ByVal value As String)

EnsureChildControls()

ibGotoPage.ImageUrl = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("设置当鼠标指针在按钮上时显示的图片.") _

> _

Public Property HoverImageUrl()Property HoverImageUrl() As String

Get

EnsureChildControls()

Return Me._HoverImageUrl

End Get

Set(ByVal value As String)

EnsureChildControls()

Me._HoverImageUrl = value

End Set

End Property

< _

Bindable(True), _

Category("Style"), _

DefaultValue(""), _

Description("设置当鼠标按下时显示的图片.") _

> _

Public Property PressedImageUrl()Property PressedImageUrl() As String

Get

EnsureChildControls()

Return Me._PressedImageUrl

End Get

Set(ByVal value As String)

EnsureChildControls()

Me._PressedImageUrl = value

End Set

End Property

< _

Bindable(True), _

Category("Size"), _

DefaultValue(""), _

Description("设置 PageSize 文本框宽度.") _

> _

Public Property PageSizeWidth()Property PageSizeWidth() As Unit

Get

EnsureChildControls()

Return txtPageSize.Width

End Get

Set(ByVal value As Unit)

EnsureChildControls()

txtPageSize.Width = value

End Set

End Property

< _

Bindable(True), _

Category("Size"), _

DefaultValue(""), _

Description("设置 PageIndex 文本框宽度.") _

> _

Public Property PageIndexWidth()Property PageIndexWidth() As Unit

Get

EnsureChildControls()

Return txtPageIndex.Width

End Get

Set(ByVal value As Unit)

EnsureChildControls()

txtPageIndex.Width = value

End Set

End Property

< _

Bindable(True), _

Category("Size"), _

DefaultValue(""), _

Description("设置 转到 按钮的宽度.") _

> _

Public Property ibGotoPageWidth()Property ibGotoPageWidth() As Unit

Get

EnsureChildControls()

Return ibGotoPage.Width

End Get

Set(ByVal value As Unit)

EnsureChildControls()

ibGotoPage.Width = value

End Set

End Property

< _

Bindable(True), _

Category("Size"), _

DefaultValue(""), _

Description("设置 转到 按钮的高度.") _

> _

Public Property ibGotoPageHeight()Property ibGotoPageHeight() As Unit

Get

EnsureChildControls()

Return ibGotoPage.Height

End Get

Set(ByVal value As Unit)

EnsureChildControls()

ibGotoPage.Height = value

End Set

End Property

< _

Bindable(True), _

Category("Text"), _

DefaultValue(""), _

Description("设置 转到 链接按钮的文字.") _

> _

Public Property lbGotoPageText()Property lbGotoPageText() As String

Get

EnsureChildControls()

Return lbGotoPage.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

lbGotoPage.Text = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置链接数据库的字符串.") _

> _

Public Property SQLConnection()Property SQLConnection() As String

Get

EnsureChildControls()

Return ViewState("SQLConnection")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("SQLConnection") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置表名.") _

> _

Public Property TableName()Property TableName() As String

Get

EnsureChildControls()

Return ViewState("TableName")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("TableName") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置分页数据的主键.") _

> _

Public Property PrimaryKeyField()Property PrimaryKeyField() As String

Get

EnsureChildControls()

Return ViewState("PrimaryKeyField")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("PrimaryKeyField") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置返回的字段.") _

> _

Public Property Field()Property Field() As String

Get

EnsureChildControls()

Return ViewState("Field")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("Field") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置 WHERE 条件.") _

> _

Public Property Where()Property Where() As String

Get

EnsureChildControls()

Return ViewState("Where")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("Where") = value

End Set

End Property

< _

Browsable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置排序方式.") _

> _

Public Property OrderBy()Property OrderBy() As String

Get

EnsureChildControls()

Return ViewState("OrderBy")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("OrderBy") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("设置分组方式.") _

> _

Public Property GroupBy()Property GroupBy() As String

Get

EnsureChildControls()

Return ViewState("GroupBy")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("GroupBy") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

TypeConverter(GetType(ControlToDataBindConverter)), _

Description("设置要分页的控件.") _

> _

Public Property ControlToPaginate()Property ControlToPaginate() As String

Get

EnsureChildControls()

Return ViewState("ControlToPaginate")

End Get

Set(ByVal value As String)

EnsureChildControls()

ViewState("ControlToPaginate") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(1), _

Description("设置当前页.") _

> _

Public Property CurrentPageIndex()Property CurrentPageIndex() As Int32

Get

EnsureChildControls()

Return ViewState("CurrentPageIndex")

End Get

Set(ByVal value As Int32)

EnsureChildControls()

ViewState("CurrentPageIndex") = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("每页显示数据的大小.") _

> _

Public Property PageSize()Property PageSize() As Int32

Get

EnsureChildControls()

If Not IsNumeric(txtPageSize.Text) Then

txtPageSize.Text = 10

Else

If CInt(txtPageSize.Text) < 1 Then

txtPageSize.Text = 10

End If

End If

Return CInt(txtPageSize.Text)

End Get

Set(ByVal value As Int32)

EnsureChildControls()

txtPageSize.Text = value

End Set

End Property

< _

Bindable(True), _

Category("Database"), _

DefaultValue(""), _

Description("将要转到的页数.") _

> _

Public Property PageIndex()Property PageIndex() As String

Get

EnsureChildControls()

Return txtPageIndex.Text

End Get

Set(ByVal value As String)

EnsureChildControls()

txtPageIndex.Text = value

End Set

End Property

< _

Bindable(False), _

Category("Database"), _

DefaultValue(""), _

TypeConverter(GetType(StoredProcedureNameConverter)), _

Description("选择存储过程。") _

> _

Public Property StoredProcedureName()Property StoredProcedureName() As String

Get

Return _StoredProcedureName

End Get

Set(ByVal Value As String)

_StoredProcedureName = Value

End Set

End Property

< _

Bindable(False), _

Category("About"), _

DefaultValue(""), _

Description("作者:江建 QQ:33512603" & vbCrLf & "编程浪子:http://vbcc.126.com") _

> _

Public ReadOnly Property About()Property About() As String

Get

Return "作者:江建 QQ:33512603" & vbCrLf & "编程浪子:http://vbcc.126.com"

End Get

End Property

<

Browsable(False)> _

Public ReadOnly Property PageCount()Property PageCount() As Int32

Get

EnsureChildControls()

Return ViewState("PageCount")

End Get

End Property

<

Browsable(False)> _

Public ReadOnly Property RecordCount()Property RecordCount() As Int32

Get

EnsureChildControls()

Return ViewState("RecordCount")

End Get

End Property

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#End Region

事件定义#Region "事件定义"

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Private Sub ibGotoPage_Click()Sub ibGotoPage_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)

If Not IsNumeric(PageIndex) Then

PageIndex = CurrentPageIndex

End If

If PageIndex < 1 Then

PageIndex = 1

ElseIf PageIndex > PageCount Then

PageIndex = PageCount

End If

CurrentPageIndex = PageIndex

Call DataBind()

End Sub

Private Sub lbGotoPage_Click()Sub lbGotoPage_Click(ByVal source As Object, ByVal e As EventArgs)

If Not IsNumeric(PageIndex) Then

PageIndex = CurrentPageIndex

End If

If PageIndex < 1 Then

PageIndex = 1

ElseIf PageIndex > PageCount Then

PageIndex = PageCount

End If

CurrentPageIndex = PageIndex

Call DataBind()

End Sub

Private Sub lbFirstPage_Click()Sub lbFirstPage_Click(ByVal source As Object, ByVal e As EventArgs)

CurrentPageIndex = 1

Call DataBind()

End Sub

Private Sub lbPrevPage_Click()Sub lbPrevPage_Click(ByVal source As Object, ByVal e As EventArgs)

If CurrentPageIndex > 1 Then

CurrentPageIndex -= 1

End If

Call DataBind()

End Sub

Private Sub lbNextPage_Click()Sub lbNextPage_Click(ByVal source As Object, ByVal e As EventArgs)

If CurrentPageIndex < PageCount Then

CurrentPageIndex += 1

End If

Call DataBind()

End Sub

Private Sub lbLastPage_Click()Sub lbLastPage_Click(ByVal source As Object, ByVal e As EventArgs)

CurrentPageIndex = PageCount

Call DataBind()

End Sub

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#End Region

下面的代码用于控件的下拉列表属性页

Public Class StoredProcedureNameConverterClass StoredProcedureNameConverter

Inherits StringConverter

'存储过程 有兴趣可以添加你自己的存储过程

'要用下拉列表编辑属性

Public Overrides Function GetStandardValuesSupported()Function GetStandardValuesSupported(ByVal context As ITypeDescriptorContext) As Boolean

Return True

End Function

'这个override返回下拉列表项。

Public Overrides Function GetStandardValues()Function GetStandardValues(ByVal context As ITypeDescriptorContext) As StandardValuesCollection

Dim StringArray As ArrayList = New ArrayList()

StringArray.Add("sys_QuickSortPaging")

StringArray.Add("sys_SortDataPager")

Return New StandardValuesCollection(StringArray)

End Function

'Return True的话只能选,Return flase可选可填

Public Overrides Function GetStandardValuesExclusive()Function GetStandardValuesExclusive(ByVal context As ITypeDescriptorContext) As Boolean

Return True

End Function

End Class

Public Class ControlToDataBindConverterClass ControlToDataBindConverter

Inherits StringConverter

'列出可以绑定的控件

'要用下拉列表编辑属性

Public Overrides Function GetStandardValuesSupported()Function GetStandardValuesSupported(ByVal context As ITypeDescriptorContext) As Boolean

Return True

End Function

'这个override返回下拉列表项。

Public Overrides Function GetStandardValues()Function GetStandardValues(ByVal context As ITypeDescriptorContext) As StandardValuesCollection

Dim StringArray As ArrayList = New ArrayList()

Dim I As Long

Dim objControl As ControlCollection

objControl = CType(context.Container.Components(0), Page).Controls

For I = 0 To objControl.Count - 1

If TypeOf objControl(I) Is GridView Or TypeOf objControl(I) Is DataList Then

StringArray.Add(objControl(I).ClientID)

End If

Next

Return New StandardValuesCollection(StringArray)

End Function

'Return True的话只能选,Return false可选可填

Public Overrides Function GetStandardValuesExclusive()Function GetStandardValuesExclusive(ByVal context As ITypeDescriptorContext) As Boolean

Return False

End Function

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航