Render Part
sgvGroupsData.RenderControl(writer);
Create Child Controls Part
sgvGroupsData = new SPGridView();
sgvGroupsData.ID = "sgvGroupsData";
sgvGroupsData.AutoGenerateColumns = false;
sgvGroupsData.Attributes.Add("RunAt", "Server");
this.Controls.Add(sgvGroupsData);
BoundField bTitle = new BoundField();
bTitle.HeaderText = "Title";
bTitle.DataField = "Title";
sgvGroupsData.Columns.Add(bTitle);
BoundField bRole = new BoundField();
bRole.HeaderText = "Role";
bRole.DataField = "Role";
sgvGroupsData.Columns.Add(bRole);
BoundField bUser = new BoundField();
bUser.HeaderText = "User";
bUser.DataField = "User";
sgvGroupsData.Columns.Add(bUser);
sgvGroupsData.DataSource = getUsersData();
sgvGroupsData.DataBind();
Binding data from groups
public DataSet getUsersData()
{
try
{
dtGroups.Columns.Add("Title");
dtGroups.Columns.Add("Role");
dtGroups.Columns.Add("User");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPControl.GetContextWeb(Context);
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb objWeb = site.OpenWeb())
{
foreach (SPGroup grp in objWeb.Groups)
{
foreach (SPUser user in grp.Users)
{
DataRow dr = dtGroups.NewRow();
dr["Title"] = user.Name.ToString();
dr["Role"] = grp.Name;
dr["User"] = user.LoginName.ToString();
dtGroups.Rows.Add(dr);
}
}
}
}
});
dsetGroups.Tables.Clear();
dsetGroups.Tables.Add(dtGroups);
return dsetGroups;
}
catch (Exception ex)
{
strError += ex.ToString();
return null;
}
}
sgvGroupsData.RenderControl(writer);
Create Child Controls Part
sgvGroupsData = new SPGridView();
sgvGroupsData.ID = "sgvGroupsData";
sgvGroupsData.AutoGenerateColumns = false;
sgvGroupsData.Attributes.Add("RunAt", "Server");
this.Controls.Add(sgvGroupsData);
BoundField bTitle = new BoundField();
bTitle.HeaderText = "Title";
bTitle.DataField = "Title";
sgvGroupsData.Columns.Add(bTitle);
BoundField bRole = new BoundField();
bRole.HeaderText = "Role";
bRole.DataField = "Role";
sgvGroupsData.Columns.Add(bRole);
BoundField bUser = new BoundField();
bUser.HeaderText = "User";
bUser.DataField = "User";
sgvGroupsData.Columns.Add(bUser);
sgvGroupsData.DataSource = getUsersData();
sgvGroupsData.DataBind();
Binding data from groups
public DataSet getUsersData()
{
try
{
dtGroups.Columns.Add("Title");
dtGroups.Columns.Add("Role");
dtGroups.Columns.Add("User");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPControl.GetContextWeb(Context);
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb objWeb = site.OpenWeb())
{
foreach (SPGroup grp in objWeb.Groups)
{
foreach (SPUser user in grp.Users)
{
DataRow dr = dtGroups.NewRow();
dr["Title"] = user.Name.ToString();
dr["Role"] = grp.Name;
dr["User"] = user.LoginName.ToString();
dtGroups.Rows.Add(dr);
}
}
}
}
});
dsetGroups.Tables.Clear();
dsetGroups.Tables.Add(dtGroups);
return dsetGroups;
}
catch (Exception ex)
{
strError += ex.ToString();
return null;
}
}
No comments:
Post a Comment