:: Professional ::
 
You are here: Blog
 

Hilbert Solutions, LLC Latest Dotnetnuke Modules...

Advanced News Ticker        Constant Contact Sign Up

 

Blog
Apr14

Written by:slhilbert
4/14/2009 11:51 AM 

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

 

Tags:

4 comment(s) so far...

Re: Bind Dotnetnuke User Information With the DNN UserID

Why are you converting an Integer (int32) using Convert.ToInt16 ? Is Integer Int16 in VB.Net? The default in C# would be Int32.

By jeff martin on  4/14/2009 2:50 PM

Re: Bind Dotnetnuke User Information With the DNN UserID

Good call. I have corrected it.

By slhilbert on  4/14/2009 2:59 PM

Re: Bind Dotnetnuke User Information With the DNN UserID

The ascx code seems botched. Where do you pass the uid to the function?

By Néstor Sánchez on  4/15/2009 7:27 AM

Re: Bind Dotnetnuke User Information With the DNN UserID

Yep, the ascx code was botched, fixed it again.

By slhilbert on  4/15/2009 10:32 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
Search Blog
Blog Archive
Terms Of Use| Privacy Statement Hilbert Solutions, LLC Since 2007