protected void ClearButton_Click(object sender, EventArgs e) { //clear all checks in table int count = HoldTable.Rows.Count; CheckBox[] c = new CheckBox[count]; for (int i = 0; i < count - 1; i++) { c[i] = (CheckBox)HoldTable.FindControl("box" + i); if (c[i].Checked) { c[i].Checked = false; } } }
protected void SubmitButton_Click(object sender, EventArgs e) { //Remove hold if checked int count = HoldTable.Rows.Count; ArrayList rowsChecked = new ArrayList(); CheckBox[] c = new CheckBox[count]; int row = 0; //get which values are checked for (int i = 0; i < count - 1; i++) { //please dont touch this //Needs to be updated from table to gridview //unless you are doing that dont change this //it will break =( c[i] = (CheckBox)HoldTable.FindControl("box" + i); if (c[i].Checked) { TableCell tc = new TableCell(); TableRow tr = new TableRow(); tc = (TableCell)c[i].Parent; tr = (TableRow)tc.Parent; string data = tc.ID; row = int.Parse(data.Substring(6, 1)); rowsChecked.Add(row); } } for (int i = 0; i < rowsChecked.Count; i++) { itemNumber = item[(int)rowsChecked[i] - i].ToString(); string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); SqlCommand cmd = new SqlCommand(); //delete the hold from the system cmd = new SqlCommand("DELETE FROM Hold WHERE [itemNumber] ='" + itemNumber + "'", con); cmd.ExecuteNonQuery(); con.Close(); item.RemoveAt((int)rowsChecked[i] - i); } for (int x = 0; x <= count; x++) { //remove from the table after deleting TableRow tr2 = new TableRow(); tr2 = (TableRow)HoldTable.FindControl("row" + x); HoldTable.Rows.Remove(tr2); } Page_Load(sender, e); } }