温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:DotNetNuke04.08.03免安装版项目源码
当前文件路径:DNN/Library/Controls/DualListControl.vb

1' 2
' DotNetNuke?- http://www.dotnetnuke.com 3
' Copyright (c) 2002-2008 4
' by DotNetNuke Corporation 5
' 6
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 7
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 8
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 9
' to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10
' 11
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 12
' of the Software. 13
' 14
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 15
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18
' DEALINGS IN THE SOFTWARE. 19
' 20
Imports System.IO 21
22
Namespace DotNetNuke.UI.UserControls 23
24
Public MustInherit Class DualListControl 25
26
Inherits Framework.UserControlBase 27
28
Private _ListBoxWidth As String = "" 29
Private _ListBoxHeight As String = "" 30
Private _Available As ArrayList 31
Private _Assigned As ArrayList 32
Private _DataTextField As String = "" 33
Private _DataValueField As String = "" 34
Private _Enabled As Boolean = True 35
36
Protected WithEvents lstAvailable As System.Web.UI.WebControls.ListBox 37
Protected WithEvents cmdAdd As System.Web.UI.WebControls.LinkButton 38
Protected WithEvents cmdRemove As System.Web.UI.WebControls.LinkButton 39
Protected WithEvents cmdAddAll As System.Web.UI.WebControls.LinkButton 40
Protected WithEvents cmdRemoveAll As System.Web.UI.WebControls.LinkButton 41
Protected Label1 As System.Web.UI.WebControls.Label 42
Protected Label2 As System.Web.UI.WebControls.Label 43
Protected WithEvents lstAssigned As System.Web.UI.WebControls.ListBox 44
45
Private MyFileName As String = "DualListControl.ascx" 46
47
48
' public properties 49
Public Property ListBoxWidth() As String 50
Get 51
ListBoxWidth = Convert.ToString(ViewState(Me.ClientID & "_ListBoxWidth")) 52
End Get 53
Set(ByVal Value As String) 54
_ListBoxWidth = Value 55
End Set 56
End Property 57
58
Public Property ListBoxHeight() As String 59
Get 60
ListBoxHeight = Convert.ToString(ViewState(Me.ClientID & "_ListBoxHeight")) 61
End Get 62
Set(ByVal Value As String) 63
_ListBoxHeight = Value 64
End Set 65
End Property 66
67
Public Property Available() As ArrayList 68
Get 69
Dim objListItem As ListItem 70
71
Dim objList As ArrayList = New ArrayList 72
73
For Each objListItem In lstAvailable.Items 74
objList.Add(objListItem) 75
Next 76
77
Available = objList 78
End Get 79
Set(ByVal Value As ArrayList) 80
_Available = Value 81
End Set 82
End Property 83
84
Public Property Assigned() As ArrayList 85
Get 86
Dim objListItem As ListItem 87
88
Dim objList As ArrayList = New ArrayList 89
90
For Each objListItem In lstAssigned.Items 91
objList.Add(objListItem) 92
Next 93
94
Assigned = objList 95
End Get 96
Set(ByVal Value As ArrayList) 97
_Assigned = Value 98
End Set 99
End Property 100
101
Public WriteOnly Property DataTextField() As String 102
Set(ByVal Value As String) 103
_DataTextField = Value 104
End Set 105
End Property 106
107
Public WriteOnly Property DataValueField() As String 108
Set(ByVal Value As String) 109
_DataValueField = Value 110
End Set 111
End Property 112
113
Public WriteOnly Property Enabled() As Boolean 114
Set(ByVal Value As Boolean) 115
_Enabled = Value 116
End Set 117
End Property 118
119
'******************************************************* 120
' 121
' The Page_Load server event handler on this page is used 122
' to populate the role information for the page 123
' 124
'******************************************************* 125
126
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 127
Try 128
129
'Localization 130
Label1.Text = Services.Localization.Localization.GetString("Available", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 131
Label2.Text = Services.Localization.Localization.GetString("Assigned", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 132
cmdAdd.ToolTip = Services.Localization.Localization.GetString("Add", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 133
cmdAddAll.ToolTip = Services.Localization.Localization.GetString("AddAll", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 134
cmdRemove.ToolTip = Services.Localization.Localization.GetString("Remove", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 135
cmdRemoveAll.ToolTip = Services.Localization.Localization.GetString("RemoveAll", Services.Localization.Localization.GetResourceFile(Me, MyFileName)) 136
137
If Not Page.IsPostBack Then 138
139
' set dimensions of control 140
If _ListBoxWidth <> "" Then 141
lstAvailable.Width = System.Web.UI.WebControls.Unit.Parse(_ListBoxWidth) 142
lstAssigned.Width = System.Web.UI.WebControls.Unit.Parse(_ListBoxWidth) 143
End If 144
If _ListBoxHeight <> "" Then 145
lstAvailable.Height = System.Web.UI.WebControls.Unit.Parse(_ListBoxHeight) 146
lstAssigned.Height = System.Web.UI.WebControls.Unit.Parse(_ListBoxHeight) 147
End If 148
149
' load available 150
lstAvailable.DataTextField = _DataTextField 151
lstAvailable.DataValueField = _DataValueField 152
lstAvailable.DataSource = _Available 153
lstAvailable.DataBind() 154
Sort(lstAvailable) 155
156
' load selected 157
lstAssigned.DataTextField = _DataTextField 158
lstAssigned.DataValueField = _DataValueField 159
lstAssigned.DataSource = _Assigned 160
lstAssigned.DataBind() 161
Sort(lstAssigned) 162
163
' set enabled 164
lstAvailable.Enabled = _Enabled 165
lstAssigned.Enabled = _Enabled 166
167
' save persistent values 168
ViewState(Me.ClientID & "_ListBoxWidth") = _ListBoxWidth 169
ViewState(Me.ClientID & "_ListBoxHeight") = _ListBoxHeight 170
171
End If 172
173
Catch exc As Exception 'Module failed to load 174
ProcessModuleLoadException(Me, exc) 175
End Try 176
End Sub 177
178
Private Sub cmdAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAdd.Click 179
180
Dim objListItem As ListItem 181
182
Dim objList As ArrayList = New ArrayList 183
184
For Each objListItem In lstAvailable.Items 185
objList.Add(objListItem) 186
Next 187
188
For Each objListItem In objList 189
If objListItem.Selected Then 190
lstAvailable.Items.Remove(objListItem) 191
lstAssigned.Items.Add(objListItem) 192
End If 193
Next 194
195
lstAvailable.ClearSelection() 196
lstAssigned.ClearSelection() 197
198
Sort(lstAssigned) 199
200
End Sub 201
202
Private Sub cmdRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRemove.Click 203
204
Dim objListItem As ListItem 205
206
Dim objList As ArrayList = New ArrayList 207
208
For Each objListItem In lstAssigned.Items 209
objList.Add(objListItem) 210
Next 211
212
For Each objListItem In objList 213
If objListItem.Selected Then 214
lstAssigned.Items.Remove(objListItem) 215
lstAvailable.Items.Add(objListItem) 216
End If 217
Next 218
219
lstAvailable.ClearSelection() 220
lstAssigned.ClearSelection() 221
222
Sort(lstAvailable) 223
224
End Sub 225
226
Private Sub cmdAddAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAddAll.Click 227
228
Dim objListItem As ListItem 229
230
For Each objListItem In lstAvailable.Items 231
lstAssigned.Items.Add(objListItem) 232
Next 233
234
lstAvailable.Items.Clear() 235
236
lstAvailable.ClearSelection() 237
lstAssigned.ClearSelection() 238
239
Sort(lstAssigned) 240
241
End Sub 242
243
Private Sub cmdRemoveAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRemoveAll.Click 244
245
Dim objListItem As ListItem 246
247
For Each objListItem In lstAssigned.Items 248
lstAvailable.Items.Add(objListItem) 249
Next 250
251
lstAssigned.Items.Clear() 252
253
lstAvailable.ClearSelection() 254
lstAssigned.ClearSelection() 255
256
Sort(lstAvailable) 257
End Sub 258
259
Private Sub Sort(ByVal ctlListBox As ListBox) 260
261
Dim arrListItems As New ArrayList 262
Dim objListItem As ListItem 263
264
' store listitems in temp arraylist 265
For Each objListItem In ctlListBox.Items 266
arrListItems.Add(objListItem) 267
Next 268
269
' sort arraylist based on text value 270
arrListItems.Sort(New ListItemComparer) 271
272
' clear control 273
ctlListBox.Items.Clear() 274
275
' add listitems to control 276
For Each objListItem In arrListItems 277
ctlListBox.Items.Add(objListItem) 278
Next 279
280
End Sub 281
282
End Class 283
284
Public Class ListItemComparer 285
Implements IComparer 286
287
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare 288
Dim a As ListItem = CType(x, ListItem) 289
Dim b As ListItem = CType(y, ListItem) 290
Dim c As New CaseInsensitiveComparer 291
Return c.Compare(a.Text, b.Text) 292
End Function 293
End Class 294
295
End Namespace 296






