0

When I'm Adding users, i want to sort them alphabetically. Could You help. Here is my code:

     SPUserCollection userzyWszyscy2 = witryna.SiteUsers;
        foreach (SPUser oUserKolejny in userzyWszyscy2)
        {

            DropDownList1.Items.Add(oUserKolejny.LoginName);
        }
1

I lean towards using Linq for this:

var listItems = from SPUser u in userzyWszyscy2
order by u.LoginName select new ListItem(u.LoginName)

DropDownList1.Items.AddRange(listItems.ToArray());

hope this helps, it is from memory without my trusty IDE to help ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.