DataGrid/DataList封装操作函数库!
2004-06-03 09:11 灵感之源 阅读(3156) 评论(4) 编辑 收藏 举报ASP.NET似乎少不了DataGrid,应用过程中多少会用到单击/双击等等事件处理,我在工作中封装了一些函数,希望对大家有用。做了多次重载,应付多种情况。
Public Enum enumControlType
ctLinkButton
ctImageButton
ctRequiredFieldValidator
ctRadioButton
ctRangeValidator
End Enum
#Region "DataGrid控制"
Public Shared Sub ConfirmDBGridItemClick(ByVal e As DataGridItemEventArgs, _
ByVal strName As String, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/27 14:38
'参数::
' :
'返回:成功,True,反之,False
'说明:
ConfirmDBGridItemClick(e.Item, strName, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, udeControlType, strToolTip)
End Sub
Public Shared Sub ConfirmDBListItemClick(ByVal e As DataListItemEventArgs, _
ByVal strName As String, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBListItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/27 14:38
'参数::
' :
'返回:成功,True,反之,False
'说明:
ConfirmDBListItemClick(e.Item, strName, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, udeControlType, strToolTip)
End Sub
Public Shared Sub ConfirmDBListItemClick(ByRef dliItem As DataListItem, _
ByVal strName As String, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBListItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
With dliItem
If .ItemIndex >= 0 Then
Select Case udeControlType
Case enumControlType.ctLinkButton
Dim o_lkbItem As LinkButton
o_lkbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_lkbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
Case enumControlType.ctImageButton
Dim o_imbItem As ImageButton
o_imbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_imbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
Case enumControlType.ctRequiredFieldValidator
Dim o_rfvItem As RequiredFieldValidator
o_rfvItem = .FindControl(strName)
ConfirmDBGridItemClick(o_rfvItem, strMessage)
Case enumControlType.ctRadioButton
Dim o_rdbItem As RadioButton
o_rdbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_rdbItem, strText)
Case enumControlType.ctRangeValidator
Dim o_rdbItem As RangeValidator
o_rdbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_rdbItem, strText)
End Select
End If
End With
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef dgiItem As DataGridItem, _
ByVal strName As String, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
With dgiItem
If .ItemIndex >= 0 Then
Select Case udeControlType
Case enumControlType.ctLinkButton
Dim o_lkbItem As LinkButton
o_lkbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_lkbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
Case enumControlType.ctImageButton
Dim o_imbItem As ImageButton
o_imbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_imbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
Case enumControlType.ctRequiredFieldValidator
Dim o_rfvItem As RequiredFieldValidator
o_rfvItem = .FindControl(strName)
ConfirmDBGridItemClick(o_rfvItem, strMessage)
Case enumControlType.ctRadioButton
Dim o_rdbItem As RadioButton
o_rdbItem = .FindControl(strName)
ConfirmDBGridItemClick(o_rdbItem, strText)
End Select
End If
End With
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef rdbItem As RadioButton, _
ByVal strText As String)
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
If Not rdbItem Is Nothing Then
With rdbItem
.Text=strText
End With
End If
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef rfvItem As RangeValidator, _
ByVal strMessage As String)
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
If Not rfvItem Is Nothing Then
With rfvItem
.ErrorMessage=strMessage
End With
End If
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef rfvItem As RequiredFieldValidator, _
ByVal strMessage As String)
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
If Not rfvItem Is Nothing Then
With rfvItem
.ErrorMessage=strMessage
End With
End If
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef imbButton As ImageButton, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
If Not imbButton Is Nothing Then
With imbButton
If blnConfirm Then
Dim o_strScript As String
If blnCustomScript Then
o_strScript = strText
Else
o_strScript = "return confirm('" & strMessage & "')"
End If
.Attributes.Add("onclick", o_strScript)
End If
.CommandName, strCommandName)
.ToolTip=strToolTip
End With
End If
End Sub
Public Shared Sub ConfirmDBGridItemClick(ByRef lkbButton As LinkButton, _
ByVal strMessage As String, _
Optional ByVal strText As String = "", _
Optional ByVal blnConfirm As Boolean = True, _
Optional ByVal blnCustomScript As Boolean = False, _
Optional ByVal strCommandName As String = "", _
Optional ByVal strToolTip As String = "")
'名称:ConfirmDBGridItemClick
'功能:确认表格行按钮(同时处理多语言)
'作者:chs
'创建:2004/4/12
'修改:2004/4/29 09:33
'参数::
' :
'返回:成功,True,反之,False
'说明:
If Not lkbButton Is Nothing Then
With lkbButton
If blnConfirm Then
Dim o_strScript As String
If blnCustomScript Then
o_strScript = strMessage 'strText
Else
o_strScript = "return confirm('" & strMessage & "')"
End If
.Attributes.Add("onclick", o_strScript)
End If
.Text=strText
.CommandName=strCommandName
.ToolTip=strToolTip
End With
End If
End Sub
#End Region