private void InsertActionPlan() { StringBuilder sb = new StringBuilder(); string str = string.Empty; Label lbl = null; TextBox txt1 = null; TextBox txt2 = null; DropDownList ddl = null; foreach (GridViewRow row in gvActionPlan.Rows) { lbl = (Label)row.Cells[0].FindControl("lblID"); txt1 = (TextBox)row.Cells[0].FindControl("txtAction"); txt2 = (TextBox)row.Cells[0].FindControl("txtDeadline"); ddl = (DropDownList)row.Cells[0].FindControl("ddlCompleted"); if (lbl != null && txt1 != null && txt2 != null && ddl != null) { if (lbl.Text != string.Empty || txt1.Text != string.Empty || txt2.Text != string.Empty || ddl.SelectedValue != "-1") { sb.Append(lbl.Text + "|$|"); sb.Append(txt1.Text + "|$|"); sb.Append(txt2.Text + "|$|"); sb.Append(ddl.SelectedValue + "|#|"); } } } str = sb.ToString(); if (str.LastIndexOf("|#|") > -1) { str = str.Substring(0, str.Length - 3); } if (str != string.Empty) { oDV = AdoUDIRS.DoActionPlan(IncidentID, str.ToString(), "|#|", "|$|"); } Response.Redirect("~/Web/ThankYou.aspx", true); /* * * using (SqlConnection connection = new SqlConnection(GetConnectionString())) * { * connection.Open(); * using (SqlCommand cmd = new SqlCommand(sb.ToString(), connection)) * { * cmd.CommandType = CommandType.Text; * cmd.ExecuteNonQuery(); * } * } * lblMessage.Text = "Records successfully saved!"; */ }