Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIExample: Treeview and RolesExample: Treeview and Roles
Previous
 
Next
New Post
2/28/2007 6:26 PM
 

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>&nbsp;</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

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIExample: Treeview and RolesExample: Treeview and Roles


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out