protected void gvSites_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Add the hyperlink DataKey x = gvSites.DataKeys[e.Row.RowIndex]; //Add the allowed check box CheckBox chkInclude = new CheckBox(); chkInclude.ID = "chkInclude" + e.Row.RowIndex; //Go to the DB to see if this is checked. OMAMLnkCategoryPortal objCategoryPortal = new OMAMLnkCategoryPortal(); objCategoryPortal.Query .Where(objCategoryPortal.Query.CategoryId == categoryId, objCategoryPortal.Query.PortalId == Convert.ToInt32(x[0].ToString())); objCategoryPortal.Query.Load(); if (objCategoryPortal.PortalId != null) { chkInclude.Checked = true; } else { chkInclude.Checked = false; } e.Row.Cells[1].Controls.Add(chkInclude); } }
protected void lnkSaveCategory_Click(object sender, EventArgs e) { if (txtCategoryId.Text.ToString() == string.Empty) { //This is an add OMAMFundCategory CategoryInfo = new OMAMFundCategory(); CategoryInfo.FundCategory = txtCategoryName.Text.ToString(); CategoryInfo.Save(); //Now add the available site list for (int i = 0; i < gvSites.Rows.Count; i++) { //CheckBox cbInclude = new CheckBox(); CheckBox cbInclude = ((CheckBox)gvSites.Rows[i].Cells[1].FindControl("chkInclude" + i)); if (cbInclude.Checked) { OMAMLnkCategoryPortal objCategoryPortal = new OMAMLnkCategoryPortal(); DataKey dKey = gvSites.DataKeys[i]; objCategoryPortal.PortalId = Convert.ToInt32(dKey[0].ToString()); objCategoryPortal.CategoryId = categoryId; objCategoryPortal.Save(); } } } else { //This is an update OMAMFundCategory CategoryInfo = new OMAMFundCategory(); CategoryInfo.Query.Where(CategoryInfo.Query.Id == Convert.ToInt16(txtCategoryId.Text.ToString())); CategoryInfo.Query.Load(); CategoryInfo.Id = Convert.ToInt32(txtCategoryId.Text.ToString()); CategoryInfo.FundCategory = txtCategoryName.Text.ToString(); CategoryInfo.Save(); //Delete all the site contents for this category item and add them again OMAMLnkCategoryPortalCollection objCategoryPortals = new OMAMLnkCategoryPortalCollection(); objCategoryPortals.Query.Where(objCategoryPortals.Query.CategoryId == categoryId); objCategoryPortals.Query.Load(); objCategoryPortals.MarkAllAsDeleted(); objCategoryPortals.Save(); //Now Add the new site/content list //Now add the available site list for (int i = 0; i < gvSites.Rows.Count; i++) { //CheckBox cbInclude = new CheckBox(); CheckBox cbInclude = ((CheckBox)gvSites.Rows[i].Cells[1].FindControl("chkInclude" + i)); if (cbInclude.Checked) { OMAMLnkCategoryPortal objCategoryPortal = new OMAMLnkCategoryPortal(); DataKey dKey = gvSites.DataKeys[i]; objCategoryPortal.PortalId = Convert.ToInt32(dKey[0].ToString()); objCategoryPortal.CategoryId = categoryId; objCategoryPortal.Save(); } } } divAddActivity.Visible = false; divCategoryList.Visible = true; LoadCategories(); categoryId = null; }