protected void btnViewRoles_Click(object sender, EventArgs e) { //Session["SystemID"] = ddlSystem2.SelectedValue; //Session["SubsystemID"] = ddlSubsystem2.SelectedValue; cblRoles.Items.Clear(); SubsystemRolesDAL subsystemDal = new SubsystemRolesDAL(); List <SubsystemRoles> rolesList = subsystemDal.GetRolesForSubsystem(Int32.Parse(ddlSystem2.SelectedValue), Int32.Parse(ddlSubsystem2.SelectedValue)); foreach (SubsystemRoles role in rolesList) { ListItem item = new ListItem(); item.Value = role.roleID.ToString(); item.Text = role.roleName; //item.CssClass = "checkboxClass"; if (role.isChecked == 1) { item.Selected = true; } else { item.Selected = false; } cblRoles.Items.Add(item); } }
protected void btnSave_Click(object sender, EventArgs e) { SubsystemRoles role = new SubsystemRoles(); SubsystemRolesDAL rolesDal = new SubsystemRolesDAL(); bool isFirstTime = true; foreach (ListItem item in cblRoles.Items) { role.roleID = Int32.Parse(item.Value); if (item.Selected) { if (isFirstTime) { rolesDal.SaveSubsystemRole(Int32.Parse(ddlSystem2.SelectedValue), Int32.Parse(ddlSubsystem2.SelectedValue), role.roleID, 1); } else { rolesDal.SaveSubsystemRole(Int32.Parse(ddlSystem2.SelectedValue), Int32.Parse(ddlSubsystem2.SelectedValue), role.roleID, 0); } role.isChecked = 1; isFirstTime = false; } } //No boxes checked if (isFirstTime) { rolesDal.SaveSubsystemRole(Int32.Parse(ddlSystem2.SelectedValue), Int32.Parse(ddlSubsystem2.SelectedValue), role.roleID, 2); } lblMessage.Text = "Items Saved " + DateTime.Now.ToLongTimeString(); lblMessage.Visible = true; }