2013-06-11 1 views
0

저는 Roles.GetAllRoles()를 사용하여 기본 .NET 멤버 자격 공급자를 사용하고 Gridview에 역할을 채 웁니다. 나는 역할을 삭제하기위한 명령 필드와 역할 자체를위한 경계 필드를 가지고있다. 내가해야 할 일은 역할 당 사용자 수를 더하는 것입니다. 역할 열은 다음과 같습니다.각 역할의 사용자 수를 알아 내기

관리자는 (4)
감독자를 (12)

내가 데이터베이스를 가져 오기 및 역할에 가치를 추가 할 RowCreated 이벤트를 사용하여 생각하고 있었는데, 사용자가이 역할을 삭제하는 것을 방지합니다. 그것을 할 수있는 더 좋은 방법이 있습니까?

편집 : 해결책 내가 필요한 것을 얻으려면 RowDataBound 이벤트를 사용해야했습니다.

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 + ")"; 
      } 
     } 

    } 

답변

0

Roles.GetUsersInRole을 사용할 수 있습니다. 예 :

If Roles.GetUsersInRole(strRole).Count > 0 Then 
    'do NOT delete this role 
End If 
+0

감사합니다. – Mario