After reading Michael Washington's Tutorial I decided to do some experimenting with the DNN Web Controls, namely the DNN Tree. I came up with a way to bind all the roles in a portal and the users within that role as child items. Then when you click on the user, a small postback is done and passes the userid to a label control. From there you could do anything, like load the user's whole profile. I hope this helps some people out, and feel free to postback any contributions.
- RoleName
-DisplayName
-DisplayName
ASCX
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Testing1.ascx.vb" Inherits="My.Modules.TestingControls.Testing1" %>
<%@ Register Assembly="DotNetNuke.WebControls" Namespace="DotNetNuke.UI.WebControls"
TagPrefix="DNN" %>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td valign="top">
<DNN:DnnTree ID="MyDNNTree" runat="server" CollapsedNodeImage="../../../Images/Plus.gif"
ExpandedNodeImage="../../../Images/Minus.gif">
</DNN:DnnTree>
</td>
<td valign="top">
<asp:Label ID="lblUserId" runat="server" Text="Label"></asp:Label> </td>
</tr>
</table>
Code Behind
Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity
Imports DotNetNuke.UI.WebControls
Namespace My.Modules.TestingControls
Partial Class Testing1
Inherits Entities.Modules.PortalModuleBase
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
MyDNNTree.ImageList.Add("../../../Images/folder.gif")
MyDNNTree.ImageList.Add("../../../Images/file.gif")
PopulateRoleTree()
End If
End Sub
Protected Sub MyDNNTree_PopulateOnDemand(ByVal source As Object, ByVal e As DotNetNuke.UI.WebControls.DNNTreeEventArgs) Handles MyDNNTree.PopulateOnDemand
PopulateChildrenTreeNodes(e.Node)
End Sub
Protected Sub MyDNNTree_NodeClick(ByVal source As Object, ByVal e As DotNetNuke.UI.WebControls.DNNTreeNodeClickEventArgs) Handles MyDNNTree.NodeClick
BindUserDetails(e.Node)
End Sub
Private Sub PopulateRoleTree()
MyDNNTree.TreeNodes.Clear()
Dim index As Integer = 0
'Get the roles for this portal
Dim arrRoles As ArrayList = DotNetNuke.Security.Membership.DNNRoleProvider.Instance().GetRoles(PortalId)
'Loop through the array of roles and add each one as a tree node
For Each role As DotNetNuke.Security.Roles.RoleInfo In arrRoles
Dim objNode As TreeNode = New TreeNode(role.RoleName)
objNode.HasNodes = True
objNode.ClickAction = eClickAction.Expand
MyDNNTree.TreeNodes.Add(objNode)
index += 1
Next
End Sub
Private Sub PopulateChildrenTreeNodes(ByVal objParent As TreeNode)
'Get an array of the Users within a role. The role is objParent.text
Dim arrUsers As ArrayList = DotNetNuke.Security.Membership.DNNRoleProvider.Instance().GetUsersByRoleName(PortalId, objParent.Text)
If arrUsers.Count > 0 Then
'Loop through the User array and add each user as a node
For Each user As DotNetNuke.Entities.Users.UserInfo In arrUsers
Dim index As Integer = 0
Dim objTreeNode As TreeNode
index = objParent.TreeNodes.Add()
objTreeNode = objParent.TreeNodes(index)
objTreeNode.Key = user.UserID 'We'll use the key to hold the userId
objTreeNode.Text = user.DisplayName
objTreeNode.ImageIndex = eImageType.Page
objTreeNode.ClickAction = eClickAction.PostBack
index += 1
Next
End If
End Sub
Private Sub BindUserDetails(ByVal objParent As TreeNode)
lblUserId.Text = objParent.Key.ToString
End Sub
Public Enum eImageType
Folder
Page
End Enum
End Class
End Namespace