コード例 #1
0
    public void BindSelectedPermission(object sender, ListViewItemEventArgs e)
    {
        KeyValuePair <string, ModelPermissionLevel> item = (KeyValuePair <string, ModelPermissionLevel>)e.Item.DataItem;

        string grpName           = item.Key;
        ModelPermissionLevel lvl = item.Value;

        // To the user, these are equivalent in terms of access
        if (lvl == ModelPermissionLevel.NotSet)
        {
            lvl = _permissionsManager.CheckGroupPermissions(_permissionsManager.GetUserGroup(DefaultGroups.AllUsers), _pid);
        }

        var row = e.Item.FindControl("DataRow");

        if (grpName == DefaultGroups.AllUsers)
        {
            ((System.Web.UI.HtmlControls.HtmlTableCell)row.Controls[0]).InnerText = PermissionsManager.ALL_USERS_LABEL;
        }
        else if (grpName == DefaultGroups.AnonymousUsers)
        {
            ((System.Web.UI.HtmlControls.HtmlTableCell)row.Controls[0]).InnerText = PermissionsManager.ANONYMOUS_USERS_LABEL;
        }

        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            DropDownList dd = (DropDownList)row.FindControl("DropdownColumn")
                              .FindControl("PermissionsDropdownList");

            foreach (ListItem li in dd.Items)
            {
                if (Int32.Parse(li.Value) == (int)lvl)
                {
                    li.Selected = true;
                    break;
                }
            }
        }
    }