protected void btnAttach_Click(object sender, EventArgs e) { int incidentid = Convert.ToInt16(Session["incidentid"].ToString()); foreach (GridViewRow gv in grdvwProblem.Rows) { string gvIDs; // Declare local variable deleteChkBxItem of Checkbox type to get the Checkbox Instance of Grid Row CheckBox deleteChkBxItem = (CheckBox)gv.FindControl("deleteRec"); // If deleteChkBxItem is Checked then ,mapped Current site to this user if (deleteChkBxItem.Checked) { int probId; gvIDs = ((Label)gv.FindControl("ProblemId")).Text.ToString(); probId = Convert.ToInt16(gvIDs); // Check if gvIDs is not null if (gvIDs != "") { objIncidentToProblem = objIncidentToProblem.Get_By_id(incidentid, probId); if (objIncidentToProblem.Incidentid == 0) { objIncidentToProblem.Incidentid = incidentid; objIncidentToProblem.Problemid = probId; objIncidentToProblem.Insert(); } } } } lblErrorMsg.Text = "Incident Request is Attached to Current Problems"; }
protected void btnAttach_Click(object sender, EventArgs e) {//Add Exception handilng try catch change by vishal 21-05-2012 try { int incidentid = Convert.ToInt32(Session["incidentid"].ToString()); foreach (GridViewRow gv in grdvwProblem.Rows) { string gvIDs; // Declare local variable deleteChkBxItem of Checkbox type to get the Checkbox Instance of Grid Row CheckBox deleteChkBxItem = (CheckBox)gv.FindControl("deleteRec"); // If deleteChkBxItem is Checked then ,mapped Current site to this user if (deleteChkBxItem.Checked) { int probId; gvIDs = ((Label)gv.FindControl("ProblemId")).Text.ToString(); probId = Convert.ToInt32(gvIDs); // Check if gvIDs is not null if (gvIDs != "") { objIncidentToProblem = objIncidentToProblem.Get_By_id(incidentid, probId); if (objIncidentToProblem.Incidentid == 0) { objIncidentToProblem.Incidentid = incidentid; objIncidentToProblem.Problemid = probId; objIncidentToProblem.Insert(); } } } } lblErrorMsg.Text = "Incident Request is Attached to Current Problems"; } catch (Exception ex) { string myScript; myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>"; Page.RegisterClientScriptBlock("MyScript", myScript); return; } }