API
Version 7.x > API > <cms:UserPicture View modes: 
User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/6/2013 4:16:22 AM
   
<cms:UserPicture
HI

I USE <cms:UserPicture IN datalist but i have error
  <asp:DataList ID="DataList1" runat="server" DataKeyField="form_1ID" DataSourceID="SqlDataSource1">
<ItemTemplate>

<li>
<h3 class="fr heading-comment"><%# MyClass.Getuser( Eval("UserID") )%><span><%#MyClass.GetCurrentCultureDate( Eval("Date")) %></span></h3>
<p class="fr clear"><cms:UserPicture ID="picUser1" runat="server" AvatarID="<%# MyClass.GetuserAvatar(int.Parse(Eval("UserID").ToString())) %>" Visible="true" /> <%# Eval("Text") %></p>
<asp:Button ID="Button1" runat="server" Text="Button" />
</li>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=MEHRDAD-PC;Initial Catalog=Asemooniha;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Form_Asemooniha_form_1] WHERE ([PostID] = @PostID) ORDER BY [Date]">
<SelectParameters>
<asp:SessionParameter Name="PostID" SessionField="PosID" Type="String" />
</SelectParameters>

</asp:SqlDataSource>

this error
[usercontrol2] The server tag is not well formed.

User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/6/2013 4:18:29 AM
   
RE:<cms:UserPicture
 public static int GetuserAvatar(object userID)
{
UserInfo cui = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserID);
if (cui != null)
{


if (cui.UserAvatarID != 0)
{
return cui.UserAvatarID;
}
else
{
return 9;
}
}
return 0;
}

User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/6/2013 4:20:37 AM
   
RE:<cms:UserPicture
 public static int GetuserAvatar(object userID)
{
UserInfo cui = UserInfoProvider.GetUserInfo(Convert.ToInt32( userID));
if (cui != null)
{


if (cui.UserAvatarID != 0)
{
return cui.UserAvatarID;
}
else
{
return 9;
}
}
return 0;
}

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/6/2013 4:41:18 AM
   
RE:<cms:UserPicture
Hi,

Could you please more explain what you are trying to do?

Also if you want to get the current user avatar ID you can use the following code:
int userAvatarID = CMSContext.CurrentUser.UserAvatarID;

Kind regards,
Richard Sustek

User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/6/2013 8:18:26 AM
   
RE:<cms:UserPicture
HI
i want to show avatar in new webpart... but in my webpart i read data of database and show avataruser by userid in my datalist asp

plz help me

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/6/2013 3:21:06 PM
   
RE:<cms:UserPicture
If I am understanding this correctly all you need to do is to get the avatar image. To do this you find a way to get the avatarguid, for me I got the userinfo of each datarow, and then got the avatarinfo from the userinfo.UserAvatarID object. After this you can access the avatarguid, which you can then use this url to fetch the image:
I used a normal image tag and set the src to the url below.

imgUser.ImageUrl = "~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?avatarguid=" + ai.AvatarGUID + "&maxsidesize=200";

Let me know if this works.

User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/10/2013 6:45:43 AM
   
RE:<cms:UserPicture
THANK YOU :)

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/7/2013 4:11:45 AM
   
RE:<cms:UserPicture
Hi,

Thank you Joshua for the great post.

I would just add an simple example of how you may obtain AvatarGUID:
int userAvatarID = CMSContext.CurrentUser.UserAvatarID;
AvatarInfo myAvatar = AvatarInfoProvider.GetAvatarInfo(userAvatarID);
string myAvatarGUID = myAvatar.AvatarGUID.ToString();

Kind regards,
Richard Sustek

User avatar
Member
Member
mehrdadilchizadeh-gmail - 11/10/2013 6:45:18 AM
   
RE:<cms:UserPicture
THANK YOU :)