protected void ListViewUsers_ItemEditing(object sender, ListViewEditEventArgs e) { ListViewUsers.EditIndex = e.NewEditIndex; PopulateListViewUsers(); if (this.ListViewUsers.EditIndex != -1) { Panel validationMsg = (Panel)this.ListViewUsers.Items[this.ListViewUsers.EditIndex].FindControl("editNameContainerIsValid"); UpdatePanel updatePanel = (UpdatePanel)this.ListViewUsers.Items[this.ListViewUsers.EditIndex].FindControl("UpdatePanelEdit"); TextBox TextBoxUserNameEdit = (TextBox)updatePanel.FindControl("TextBoxUsernameEdit"); CheckBoxList CheckBoxListRolesOfUser = (CheckBoxList)updatePanel.FindControl("CheckBoxListRolesOfUser"); Literal ListeralApplicationName = (Literal)updatePanel.FindControl("LiteralAppNameEdit"); List <String> userRolesList = RolesBLL.GetRolesForUserByApplication(ListeralApplicationName.Text, TextBoxUserNameEdit.Text); List <String> applicationRolesList = RolesBLL.GetRolesByApplication(ListeralApplicationName.Text); validationMsg.Visible = false; foreach (string applicationRole in applicationRolesList) { System.Web.UI.WebControls.ListItem listItem = new System.Web.UI.WebControls.ListItem(applicationRole, "", true); foreach (string userRole in userRolesList) { if (applicationRole == userRole) { listItem.Selected = true; } } CheckBoxListRolesOfUser.Items.Add(listItem); } } }