Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, March 19, 2012

Binding Users to GridView from a Specific SharePoint Group without a single line of Loop.


Ascx
<asp:GridView ID="dgvUsers" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Display Name" DataField="Name" />
<asp:BoundField HeaderText="UserName" DataField="LoginName" />
<asp:BoundField HeaderText="EmailID" DataField="Email" />
</Columns>
</asp:GridView>
<asp:Label ID="lblErrorMessage" runat="server"></asp:Label>

Ascx.cs
try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWeb currentWeb = SPContext.Current.Web;
                    SPGroup selectedGroup = currentWeb.Groups["PRASAD KINGDOM Owners"];
                    dgvUsers.DataSource = selectedGroup.Users;
                    dgvUsers.DataBind();
                });
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.ToString();
            }




No comments:

Post a Comment