Often times when working on a Dotnetnuke module I find myself databinding all sorts of information to my module. This information usually includes a Dotnetnuke Username or a user’s first and last name. I usually store the UserID of the user and return that number from the database to the module. Here is a simple little function that I have written that allows me to display any part of the user’s information on the module.
First, here is the code that you will place in your .ascx file where you want the user information to appear.
<asp:Label runat="server"ID="lblSubmitter" Text='<%#BindName(Container.DataItem("UserID")) %>'></asp:Label>Next, you will need to place this function into your .acsx.vb file. This function is by no means perfect and I am sure there are many better ways to do this, but this works:
'Passing in the UserId of a DNN user
Function BindName(ByVal uid As Object) As String
'Checking to make sure the userid isn't a dbnull or a something less than 0
If ((IsDBNull(uid) = False) And ( Convert.ToInt32(uid) > 0)) Then
Dim UserID As Integer = Convert.ToInt32(uid)
Dim usercontroller As New DotNetNuke.Entities.Users.UserController
Dim userinfo As New DotNetNuke.Entities.Users.UserInfo
'Getting the user information
userinfo = usercontroller.GetUser(PortalId, UserID, False)
'Returning the user's nane
Return userinfo.LastName & ", " & userinfo.FirstName
Else
Return ""
End If
End Function