I am creating a web part on SharePoint that shows site owners and their email addresses. I am able to show that information in a listbox, but I would rather do it in a gridview. When I change my code to display the info in a gridview, the gridview does not display.
Here is the code I have:
namespace DisplaySiteOwnersVWP.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
string mySiteURL = "my Site URL goes here";
DataTable dtTable = new DataTable();
public VisualWebPart1()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
dtTable.Columns.Add("Name");
dtTable.Columns.Add("Email");
using (SPSite site = new SPSite(mySiteURL))
{
using (SPWeb web = site.RootWeb)
{
SPGroup ownerGroup = web.AssociatedOwnerGroup;
if (ownerGroup != null)
{
foreach (SPUser user in ownerGroup.Users)
{
if (user.IsSiteAdmin == true)
{
DataRow dtRow = dtTable.NewRow();
dtRow["Name"] = user.Name;
dtRow["Email"] = user.Email;
}
}
}
gvOwners.DataSource = dtTable;
gvOwners.DataBind();
}
}
} } }