//******************************************************* // // The RolesList_ItemCommand server event handler on this page // is used to handle the user editing and deleting roles // from the RolesList asp:datalist control // //******************************************************* private void RolesList_ItemCommand(object sender, DataListCommandEventArgs e) { AdminDB admin = new AdminDB(); int roleId = (int)rolesList.DataKeys[e.Item.ItemIndex]; if (e.CommandName == "edit") { // Set editable list item index if "edit" button clicked next to the item rolesList.EditItemIndex = e.Item.ItemIndex; // Repopulate the datalist control BindData(); } else if (e.CommandName == "apply") { // Apply changes String _roleName = ((TextBox)e.Item.FindControl("roleName")).Text; // update database admin.UpdateRole(roleId, _roleName); // Disable editable list item access rolesList.EditItemIndex = -1; // Repopulate the datalist control BindData(); } else if (e.CommandName == "delete") { // update database admin.DeleteRole(roleId); // Ensure that item is not editable rolesList.EditItemIndex = -1; // Repopulate list BindData(); } else if (e.CommandName == "members") { // Save role name changes first String _roleName = ((TextBox)e.Item.FindControl("roleName")).Text; admin.UpdateRole(roleId, _roleName); // redirect to edit page Response.Redirect("~/Admin/SecurityRoles.aspx?roleId=" + roleId + "&rolename=" + _roleName + "&tabindex=" + tabIndex + "&tabid=" + tabId); } }