DataGrid/DataList封装操作函数库

时间:2006/5/28 18:19:52      阅读:2664          

      ASP.NET似乎少不了DataGrid,应用过程中多少会用到单击/双击等等事件处理,我在工作中封装了一些函数,希望对大家有用。做了多次重载,应付多种情况。(转载)

  1Public Enum enumControlType
  2        ctLinkButton
  3        ctImageButton
  4        ctRequiredFieldValidator
  5        ctRadioButton
  6        ctRangeValidator
  7    End Enum
  8
  9#Region "DataGrid控制"
 10    Public Shared Sub ConfirmDBGridItemClick(ByVal e As DataGridItemEventArgs, _
 11                                             ByVal strName As String, _
 12                                             ByVal strMessage As String, _
 13                                             Optional ByVal strText As String = "", _
 14                                             Optional ByVal blnConfirm As Boolean = True, _
 15                                             Optional ByVal blnCustomScript As Boolean = False, _
 16                                             Optional ByVal strCommandName As String = "", _
 17                                             Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
 18                                             Optional ByVal strToolTip As String = "")
 19        '名称:ConfirmDBGridItemClick
 20        '功能:确认表格行按钮(同时处理多语言)
 21        '作者:chs
 22        '创建:2004/4/12
 23        '修改:2004/4/27 14:38
 24        '参数::
 25        '
 26        '返回:成功,True,反之,False
 27        '说明:
 28        ConfirmDBGridItemClick(e.Item, strName, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, udeControlType, strToolTip)
 29    End Sub
 30
 31    Public Shared Sub ConfirmDBListItemClick(ByVal e As DataListItemEventArgs, _
 32                                             ByVal strName As String, _
 33                                             ByVal strMessage As String, _
 34                                             Optional ByVal strText As String = "", _
 35                                             Optional ByVal blnConfirm As Boolean = True, _
 36                                             Optional ByVal blnCustomScript As Boolean = False, _
 37                                             Optional ByVal strCommandName As String = "", _
 38                                             Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
 39                                             Optional ByVal strToolTip As String = "")
 40        '名称:ConfirmDBListItemClick
 41        '功能:确认表格行按钮(同时处理多语言)
 42        '作者:chs
 43        '创建:2004/4/12
 44        '修改:2004/4/27 14:38
 45        '参数::
 46        '
 47        '返回:成功,True,反之,False
 48        '说明:
 49        ConfirmDBListItemClick(e.Item, strName, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, udeControlType, strToolTip)
 50    End Sub
 51
 52    Public Shared Sub ConfirmDBListItemClick(ByRef dliItem As DataListItem, _
 53                                             ByVal strName As String, _
 54                                             ByVal strMessage As String, _
 55                                             Optional ByVal strText As String = "", _
 56                                             Optional ByVal blnConfirm As Boolean = True, _
 57                                             Optional ByVal blnCustomScript As Boolean = False, _
 58                                             Optional ByVal strCommandName As String = "", _
 59                                             Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
 60                                             Optional ByVal strToolTip As String = "")
 61        '名称:ConfirmDBListItemClick
 62        '功能:确认表格行按钮(同时处理多语言)
 63        '作者:chs
 64        '创建:2004/4/12
 65        '修改:2004/4/29 09:33
 66        '参数::
 67        '
 68        '返回:成功,True,反之,False
 69        '说明:
 70
 71        With dliItem
 72            If .ItemIndex >= 0 Then
 73                Select Case udeControlType
 74                    Case enumControlType.ctLinkButton
 75                        Dim o_lkbItem As LinkButton
 76                        o_lkbItem = .FindControl(strName)
 77                        ConfirmDBGridItemClick(o_lkbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
 78                    Case enumControlType.ctImageButton
 79                        Dim o_imbItem As ImageButton
 80                        o_imbItem = .FindControl(strName)
 81                        ConfirmDBGridItemClick(o_imbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
 82                    Case enumControlType.ctRequiredFieldValidator
 83                        Dim o_rfvItem As RequiredFieldValidator
 84                        o_rfvItem = .FindControl(strName)
 85                        ConfirmDBGridItemClick(o_rfvItem, strMessage)
 86                    Case enumControlType.ctRadioButton
 87                        Dim o_rdbItem As RadioButton
 88                        o_rdbItem = .FindControl(strName)
 89                        ConfirmDBGridItemClick(o_rdbItem, strText)
 90                    Case enumControlType.ctRangeValidator
 91                        Dim o_rdbItem As RangeValidator
 92                        o_rdbItem = .FindControl(strName)
 93                        ConfirmDBGridItemClick(o_rdbItem, strText)
 94                End Select
 95            End If
 96        End With
 97    End Sub
 98
 99    Public Shared Sub ConfirmDBGridItemClick(ByRef dgiItem As DataGridItem, _
100                                             ByVal strName As String, _
101                                             ByVal strMessage As String, _
102                                             Optional ByVal strText As String = "", _
103                                             Optional ByVal blnConfirm As Boolean = True, _
104                                             Optional ByVal blnCustomScript As Boolean = False, _
105                                             Optional ByVal strCommandName As String = "", _
106                                             Optional ByVal udeControlType As enumControlType = enumControlType.ctLinkButton, _
107                                             Optional ByVal strToolTip As String = "")
108        '名称:ConfirmDBGridItemClick
109        '功能:确认表格行按钮(同时处理多语言)
110        '作者:chs
111        '创建:2004/4/12
112        '修改:2004/4/29 09:33
113        '参数::
114        '
115        '返回:成功,True,反之,False
116        '说明:
117
118        With dgiItem
119            If .ItemIndex >= 0 Then
120                Select Case udeControlType
121                    Case enumControlType.ctLinkButton
122                        Dim o_lkbItem As LinkButton
123                        o_lkbItem = .FindControl(strName)
124                        ConfirmDBGridItemClick(o_lkbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
125                    Case enumControlType.ctImageButton
126                        Dim o_imbItem As ImageButton
127                        o_imbItem = .FindControl(strName)
128                        ConfirmDBGridItemClick(o_imbItem, strMessage, strText, blnConfirm, blnCustomScript, strCommandName, strToolTip)
129                    Case enumControlType.ctRequiredFieldValidator
130                        Dim o_rfvItem As RequiredFieldValidator
131                        o_rfvItem = .FindControl(strName)
132                        ConfirmDBGridItemClick(o_rfvItem, strMessage)
133                    Case enumControlType.ctRadioButton
134                        Dim o_rdbItem As RadioButton
135                        o_rdbItem = .FindControl(strName)
136                        ConfirmDBGridItemClick(o_rdbItem, strText)
137                End Select
138            End If
139        End With
140    End Sub
141
142    Public Shared Sub ConfirmDBGridItemClick(ByRef rdbItem As RadioButton, _
143                                             ByVal strText As String)
144        '名称:ConfirmDBGridItemClick
145        '功能:确认表格行按钮(同时处理多语言)
146        '作者:chs
147        '创建:2004/4/12
148        '修改:2004/4/29 09:33
149        '参数::
150        '
151        '返回:成功,True,反之,False
152        '说明:
153
154        If Not rdbItem Is Nothing Then
155            With rdbItem
156                .Text=strText
157            End With
158        End If
159    End Sub
160
161    Public Shared Sub ConfirmDBGridItemClick(ByRef rfvItem As RangeValidator, _
162                                             ByVal strMessage As String)
163        '名称:ConfirmDBGridItemClick
164        '功能:确认表格行按钮(同时处理多语言)
165        '作者:chs
166        '创建:2004/4/12
167        '修改:2004/4/29 09:33
168        '参数::
169        '
170        '返回:成功,True,反之,False
171        '说明:
172
173        If Not rfvItem Is Nothing Then
174            With rfvItem
175                .ErrorMessage=strMessage
176            End With
177        End If
178    End Sub
179
180    Public Shared Sub ConfirmDBGridItemClick(ByRef rfvItem As RequiredFieldValidator, _
181                                             ByVal strMessage As String)
182        '名称:ConfirmDBGridItemClick
183        '功能:确认表格行按钮(同时处理多语言)
184        '作者:chs
185        '创建:2004/4/12
186        '修改:2004/4/29 09:33
187        '参数::
188        '
189        '返回:成功,True,反之,False
190        '说明:
191
192        If Not rfvItem Is Nothing Then
193            With rfvItem
194                .ErrorMessage=strMessage
195            End With
196        End If
197    End Sub
198
199    Public Shared Sub ConfirmDBGridItemClick(ByRef imbButton As ImageButton, _
200                                             ByVal strMessage As String, _
201                                             Optional ByVal strText As String = "", _
202                                             Optional ByVal blnConfirm As Boolean = True, _
203                                             Optional ByVal blnCustomScript As Boolean = False, _
204                                             Optional ByVal strCommandName As String = "", _
205                                             Optional ByVal strToolTip As String = "")
206        '名称:ConfirmDBGridItemClick
207        '功能:确认表格行按钮(同时处理多语言)
208        '作者:chs
209        '创建:2004/4/12
210        '修改:2004/4/29 09:33
211        '参数::
212        '
213        '返回:成功,True,反之,False
214        '说明:
215
216        If Not imbButton Is Nothing Then
217            With imbButton
218                If blnConfirm Then
219                    Dim o_strScript As String
220                    If blnCustomScript Then
221                        o_strScript = strText
222                    Else
223                        o_strScript = "return confirm('" & strMessage & "')"
224                    End If
225                    .Attributes.Add("onclick", o_strScript)
226                End If
227                .CommandName, strCommandName)
228                .ToolTip=strToolTip
229            End With
230        End If
231    End Sub
232
233    Public Shared Sub ConfirmDBGridItemClick(ByRef lkbButton As LinkButton, _
234                                             ByVal strMessage As String, _
235                                             Optional ByVal strText As String = "", _
236                                             Optional ByVal blnConfirm As Boolean = True, _
237                                             Optional ByVal blnCustomScript As Boolean = False, _
238                                             Optional ByVal strCommandName As String = "", _
239                                             Optional ByVal strToolTip As String = "")
240        '名称:ConfirmDBGridItemClick
241        '功能:确认表格行按钮(同时处理多语言)
242        '作者:chs
243        '创建:2004/4/12
244        '修改:2004/4/29 09:33
245        '参数::
246        '
247        '返回:成功,True,反之,False
248        '说明:
249
250        If Not lkbButton Is Nothing Then
251            With lkbButton
252                If blnConfirm Then
253                    Dim o_strScript As String
254                    If blnCustomScript Then
255                        o_strScript = strMessage 'strText
256                    Else
257                        o_strScript = "return confirm('" & strMessage & "')"
258                    End If
259                    .Attributes.Add("onclick", o_strScript)
260                End If
261                .Text=strText
262                .CommandName=strCommandName
263                .ToolTip=strToolTip
264            End With
265        End If
266    End Sub
267#End Region
评论
  • Re:DataGrid/DataList封装操作函数库  (2007/5/11 13:31:19) by hy007 
    怎么没有C#的类
标 题:
 
姓 名:
 
主 页:

验证码:

评论:
 

Because of the cache,you may see your comments several minutes later.