I'm using the default .NET Membership Provider and filling a Gridview with roles, using Roles.GetAllRoles(). I have a commandfield to delete roles and a boundfield for the role itself. What I need to do is to add the number of users per role, the role column would look like this;
Administrators(4)
Supervisors(12)
To prevent deleting a role that has users, I was thinking of using the RowCreated event to fetch the database and add the value to the roles. Is there a better way to do it?
Edit: Solution To achieve what I need I had to use RowDataBound event.
protected void RoleList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string roleName = ((Label)e.Row.FindControl("RoleNameLabel")).Text;
if (roleName.Trim().Length > 0 && Roles.RoleExists(roleName))
{
Int32 roleCount = Roles.GetUsersInRole(roleName).Count();
((Label)e.Row.FindControl("RoleNameLabel")).Text += "(" + roleCount + ")";
}
}
}