Work with people picker.
<SharePoint:PeopleEditor ID="pplSendTo" runat="server" CssClass="ms-inputuserfield" Width="250px" SelectionSet="User,SPGroup" />
* Selection set is used to mention whether people editor should accept user and spgroup.
Get values from people editor
Users = "";
UserID = "";
if (pplSendTo.ResolvedEntities.Count > 0 && pplSendTo.IsValid)
{
int usercount = pplSendTo.ResolvedEntities.Count;
for (int i = 0; i < usercount; i++)
{
PickerEntity peEntity = pplSendTo.ResolvedEntities[i] as PickerEntity;
SPUser ouser = SPContext.Current.Web.EnsureUser(peEntity.Key);
if (Users == "" && UserID == "")
{
Users = Convert.ToString(ouser);
UserID = Convert.ToString(ouser.ID);
}
else
{
Users = Users + "," + Convert.ToString(ouser);
UserID = UserID + "," + Convert.ToString(ouser.ID);
}
}
}
This will help you to get single user as well as multiple users.
Bind values into people editor.
<SharePoint:PeopleEditor ID="pplSendTo" runat="server" CssClass="ms-inputuserfield" Width="250px" SelectionSet="User,SPGroup" />
* Selection set is used to mention whether people editor should accept user and spgroup.
Get values from people editor
Users = "";
UserID = "";
if (pplSendTo.ResolvedEntities.Count > 0 && pplSendTo.IsValid)
{
int usercount = pplSendTo.ResolvedEntities.Count;
for (int i = 0; i < usercount; i++)
{
PickerEntity peEntity = pplSendTo.ResolvedEntities[i] as PickerEntity;
SPUser ouser = SPContext.Current.Web.EnsureUser(peEntity.Key);
if (Users == "" && UserID == "")
{
Users = Convert.ToString(ouser);
UserID = Convert.ToString(ouser.ID);
}
else
{
Users = Users + "," + Convert.ToString(ouser);
UserID = UserID + "," + Convert.ToString(ouser.ID);
}
}
}
This will help you to get single user as well as multiple users.
Bind values into people editor.
ArrayList arrList = new ArrayList();
_pickerEntity = new PickerEntity(); // PickerEntitiy use
using Microsoft.SharePoint.WebControls
SPFieldUserValueCollection UserCollection = new
SPFieldUserValueCollection();
if
(!string.IsNullOrEmpty(Convert.ToString(dr2["SendToUsersName"])))
{
pplSendTo.Visible = true;
SPUser ouser = null;
string[] user =
Convert.ToString(dr2["SendToUsersName"]).Split(',');
SPContext.Current.Web.AllowUnsafeUpdates = true;
SPGroupCollection groupColl = SPContext.Current.Web.Groups;
for (int k = 0; k < user.Length; k++)
{
Boolean value = false;
_pickerEntity = new PickerEntity();
foreach (SPGroup ogroup in groupColl)
{
if (Convert.ToString(ogroup) == user[k])
{
value = true;
_pickerEntity.Key = ogroup.LoginName;
arrList.Add(_pickerEntity);
break;
}
}
if (!value)
{
ouser = SPContext.Current.Web.SiteUsers[user[k]];
_pickerEntity.Key = ouser.LoginName;
arrList.Add(_pickerEntity);
}
}
pplSendTo.UpdateEntities(arrList);
this will help you to bind both users and groups into a people picker
No comments:
Post a Comment