Ejemplo n.º 1
0
        private void Page_PreRender()
        {
            // Load the User Roles into checkboxes.
            UserRolesCheckBoxList.DataSource = Roles.GetAllRoles();
            UserRolesCheckBoxList.DataBind();

            //// Disable checkboxes if appropriate:
            //if (UserInfo.CurrentMode != DetailsViewMode.Edit)
            //{
            //  foreach (ListItem checkbox in UserRoles.Items)
            //  {
            //    checkbox.Enabled = false;
            //  }
            //}

            // Bind these checkboxes to the User's own set of roles.
            string _userName = Request.QueryString["user"];

            string[] _userRoles = Roles.GetRolesForUser(_userName);
            foreach (string role in _userRoles)
            {
                ListItem checkbox = UserRolesCheckBoxList.Items.FindByValue(role);
                checkbox.Selected = true;
            }
        }
Ejemplo n.º 2
0
        protected override void OnInit(EventArgs e)
        {
            string userName = Page.RouteData.Values["user_name"].ToString();

            if (String.IsNullOrEmpty(userName))
            {
                userName = Page.Request.QueryString["user_name"];
                if (String.IsNullOrEmpty(userName))
                {
                    Response.StatusCode = 404;
                    Response.End();
                }
            }

            user = MADUsers.GetUser(userName);
            if (user == null)
            {
                Response.StatusCode = 404;
                Response.End();
            }
            allRoles  = MADRoles.GetAllRoles();
            userRoles = MADRoles.GetRolesForUser(userName);

            UserRolesCheckBoxList.AutoPostBack          = true;
            UserRolesCheckBoxList.SelectedIndexChanged += UserRolesCheckBoxList_SelectedIndexChanged;
            UserRolesCheckBoxList.DataSource            = allRoles;
            UserRolesCheckBoxList.DataTextField         = "RoleName";
            UserRolesCheckBoxList.DataBind();

            foreach (ListItem item in UserRolesCheckBoxList.Items)
            {
                item.Selected = userRoles.Contains(
                    allRoles.Where(role => role.RoleName == item.Text)
                    .FirstOrDefault()
                    );
            }
        }