[DNN通用控件]DualListControl介绍

DualListControl

[DNN通用控件]DualListControl介绍

简介:
它是个双列表框选择控件。它适用于在一个指定的范围内选择一部所需要的内容。在DotNetNuke程序中他可以通用,而且使用简单,只用设置好相应的属性即可。例如:要做一个授权的功能的时候,就可以在Available列表中读取系统所有的角色,将需要被授权的角色移动到Assigned列表中。

位置:
DNN目录\controls\DualListControl.ascx

属性:
ListBoxWidth:类型String,列表框宽度
ListBoxHeight:类型String,列表框宽度
Available:类型ArrayList,可供选择的内容
Assigned:类型ArrayList,选定的内容
DataTextField:类型String,列表框文本字段
DataValueField:类型String,列表框值字段
Enabled:类型Boolean,是否有效

使用方法:
1、首先在需要应用的页面中注册这个控件,如:
<%@ Register TagPrefix="Portal" TagName="DualList" Src="~/controls/DualListControl.ascx" %>
2、在需要用到位置写下如下的代码,如:

< portal:duallist  id ="ctlAdminRoles"  runat ="server"  ListBoxWidth ="130"  ListBoxHeight ="130"  DataValueField ="RoleName"  DataTextField ="RoleName" ></ portal:duallist >

3、在后台代码中声明该控件

Protected   WithEvents  ctlAdminRoles  As  DotNetNuke.UI.UserControls.DualListControl

4、在后台代码中分别绑定Available和Assigned的ArrayList,如:

Dim  objRoles  As   New  RoleController
Dim  arrSysRoles  As   New  ArrayList
' 获取当前站点所有的角色
arrSysRoles  =  objRoles.GetPortalRoles(PortalId)

Dim  arrAvailableAdminRoles  As   New  ArrayList
Dim  arrAssignedAdminRoles  As   New  ArrayList

arrAvailableAdminRoles 
=  arrSysRoles
' 当不是新建时,初始化已选定角色ArrayList,在可选择角色ArrayList中派出已选择部分
'
objInfo.AdminRoles是以分号分隔的角色名
'
ctlAdminRoles:DualListControl
If   Not  objInfo  Is   Nothing   Then
    
' 获取已经选定的角色
     Dim  arrAdminRoles  As   String ()  =  objInfo.AdminRoles.Split( " ; " )
    
Dim  RoleName  As   String
    
For   Each  RoleName  In  arrAdminRoles
        
Dim  objRole  As   New  RoleInfo
        objRole.RoleName 
=  RoleName
        arrAssignedAdminRoles.Add(objRole)
    
Next
    
For   Each  objAvailableRole  As  RoleInfo  In  arrAvailableAdminRoles
        
For   Each  objAssignedRole  As  RoleInfo  In  arrAssignedAdminRoles
            
If  objAvailableRole.RoleName  =  objAssignedRole.RoleName  Then
                arrAvailableAdminRoles.Remove(objAvailableRole)
            
End   If
        
Next
    
Next
End   If

ctlAdminRoles.Available 
=  arrAvailableAdminRoles
ctlAdminRoles.Assigned 
=  arrAssignedAdminRoles
ctlAdminRoles.DataBind()

更正如下:
 
               Dim arrAdminRoles As String() = "已选择角色1;已选择角色2;"
                For Each RoleName As String In arrAdminRoles
                    If RoleName.Trim().Length > 0 Then
                        Dim objRole As New RoleInfo
                        objRole.RoleName = RoleName
                        arrAssignedAdminRoles.Add(objRole)
                    End If
                Next
               'arrSysRoles:全部角色
                For Each objAvailableRole As RoleInfo In arrSysRoles
                    Dim IsInAssigned As Boolean = False
                    For Each objAssignedRole As RoleInfo In arrAssignedAdminRoles
                        If objAvailableRole.RoleName = objAssignedRole.RoleName Then
                            IsInAssigned = True
                            Exit For
                        End If
                    Next
                    If Not IsInAssigned Then
                        arrAvailableAdminRoles.Add(objAvailableRole)
                    End If
                Next

            ctlAdminRoles.Available = arrAvailableAdminRoles
            ctlAdminRoles.Assigned = arrAssignedAdminRoles
            ctlAdminRoles.DataBind()


5、从控件中获取选定项

' strAdminRoles:以分号分隔的角色名
'
ctlAdminRoles:DualListControl
Dim  strAdminRoles  As   String   =   String .Empty
For   Each  objItem  As  ListItem  In  ctlAdminRoles.Assigned
    strAdminRoles 
=  strAdminRoles  +   " ; "   +  objItem.Text
Next
strAdminRoles 
=  strAdminRoles.Substring( 1 )


 更正如下:

' strAdminRoles:以分号分隔的角色名
'
ctlAdminRoles:DualListControl
Dim  strAdminRoles  As   String   =   String .Empty
For   Each  objItem  As  ListItem  In  ctlAdminRoles.Assigned
    strAdminRoles 
=  strAdminRoles    +  objItem.Text + ";"
Next

你可能感兴趣的:(list)