views:

260

answers:

2

Hello All,

We have an UI where user selects a department. It goes into a List item. We have separate SharePoint user groups for each department.

I want to populate the users in the SharePoint group in one of the list Item. So now based on department selected I need to populate the List Item.

Please help me in doing this. I am able to get all the users in a group using:

        DropDownList ddl = new DropDownList();
        ArrayList al = new ArrayList();
        SPWeb web = SPContext.Current.Web;
        SPGroupCollection grpCln = web.Groups;
        foreach (SPGroup grp in grpCln)
        {
            if (grp.Name == "Viewers")
            {
                foreach (SPUser user in grp.Users)
                {
                    al.Add(user.Name);
                }
            }
        }
        ddl.DataSource = al;
        ddl.DataBind();
+2  A: 

I asked you in the comments, but the solution to these cases are usually Custom List Field Iterators to override your actual "Users" control, or you can also add a custom site column and hook it to your list dynamically filtering its content when rendering.

F.Aquino
A: 

And what do you want to with that dropdown later? store the selection? If so, you are better of creating a custom field type / fieldcontrol, that includes the department selector and a second select that is updated when the department changes. Then save the selection as the field's value.

The nicest way to do this of course would be through AJAX (jQuery), so the page doesn't need a refresh when the department changes.

Colin