How to get user custom field value by userid in ascx transformation

Vasyl Chepil asked on August 25, 2016 14:24

I need to get User custom field value by userid in ascx transformation.

Code like <%# GlobalObjects.Users.Where("UserID="+ToInt( Eval("UserId"), 0 )).GetValue("my_field") %> does not work.

How to get user custom field value by userid in ascx transformation?

Correct Answer

Jan Hermann answered on August 25, 2016 15:00

Your code is for Text/XML transformation except for that note from Roman. You need this one:

<%# CMS.Membership.UserInfoProvider.GetUserInfo(CMS.Helpers.ValidationHelper
.GetInteger(Eval("UserId"),0)).GetValue("my_field") %>
0 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on August 25, 2016 14:52 (last edited on August 25, 2016 14:52)

Where returns a collection, so you can't use GetValue with it. You need something like FirstOrDefault, which will return you single object.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 25, 2016 14:55

Try this:

CMS.Membership.UserInfoProvider.GetUserInfo(ValidationHelper.GetInteger(Eval("UserID"), -1)).GetStringValue("YourColumn", "")

0 votesVote for this answer Mark as a Correct answer

Vasyl Chepil answered on August 25, 2016 15:01 (last edited on August 25, 2016 15:02)

it returns

error CS0103: The name 'GlobalObjects' does not exist in the current context

So I don't think that error is in FirstOrDefault

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.