protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { //Get the selected Row int currentRowIndex = Convert.ToInt32(e.CommandArgument); //GridViewRow row = GridView1.Rows[currentRowIndex]; //Get the DataKey name values for the selected row int partnerIndicatorId = int.Parse(this.GridView1.DataKeys[currentRowIndex].Values["partner_indicator_id"].ToString()); string indicator = (from data in db.partner_indicators where data.partner_indicator_id == partnerIndicatorId select data.indicator).FirstOrDefault(); if (e.CommandName == "plan") { //Clear the datatable of previous data and make it ready for new data dt.Clear(); ViewState["prd"] = dt; SavePeriodToDbBtn.Visible = false; this.BindGrid(); ModalPlanHeaderLabel.Text = indicator; HiddenPlanIndicatorID.Value = partnerIndicatorId.ToString(); ScriptManager.RegisterStartupScript( Page, Page.GetType(), "planModal", "$('#planModal').modal('show');", true); } if (e.CommandName == "disaggregate") { IndicatorLabel.Text = indicator.Trim(); IndicatorIDHiddenField.Value = partnerIndicatorId.ToString(); EntityDataSource3.WhereParameters["project_indicator_id"].DefaultValue = partnerIndicatorId.ToString(); DisaggragationView.DataBind(); ScriptManager.RegisterStartupScript( Page, Page.GetType(), "disaggragateModal", "$('#disaggragateModal').modal('show');", true); } }
protected void SaveDisaggregationButton_Click(object sender, EventArgs e) { try { if (IndicatorIDHiddenField.Value != null) { if (Disaggregation3DropDown.SelectedItem != null) { if (Disaggregation3DropDown.SelectedItem.Value == "0" || Disaggregation3DropDown.SelectedItem.Value == "new") { if (Disaggregation2DropDown.SelectedItem.Value == "0" || Disaggregation2DropDown.SelectedItem.Value == "new") { if (Disaggregation1DropDown.SelectedItem.Value == "0" || Disaggregation1DropDown.SelectedItem.Value == "new") { //Nothing to save return; } else { //Save the first disaggre int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } else { //Save the second disagr int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation2DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } else { //Save the thrid disagrr int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation3DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } else if (Disaggregation2DropDown.SelectedItem != null) { if (Disaggregation2DropDown.SelectedItem.Value == "0" || Disaggregation2DropDown.SelectedItem.Value == "new") { if (Disaggregation1DropDown.SelectedItem.Value == "0" || Disaggregation1DropDown.SelectedItem.Value == "new") { //Nothing to save return; } else { //Save the first disaggre int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } else { //Save the second disagr int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation2DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } else if (Disaggregation1DropDown.SelectedItem != null) { if (Disaggregation1DropDown.SelectedItem.Value == "0" || Disaggregation1DropDown.SelectedItem.Value == "new") { //Nothing to save return; } else { //Save the first disaggre int projIndicatorId = int.Parse(IndicatorIDHiddenField.Value.Trim()); int disagId = int.Parse(Disaggregation1DropDown.SelectedItem.Value.Trim()); project_indicator_disaggregation newDisaggregation = new project_indicator_disaggregation(); newDisaggregation.project_indicator_id = projIndicatorId; newDisaggregation.disaggregation_id = disagId; db.project_indicator_disaggregation.Add(newDisaggregation); } } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (db.SaveChanges() > 0) { db.SaveChanges(); DisaggragationView.DataBind(); } } }