0

I want to remove all the values that I have unchecked on data grid with a Cancel button.I know how to do it with the checked ones but how can I do it in the unchecked rows?

here is my code for the checkeded with the button Proceed

  foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
            if (chkRow.Checked)
            {
                con.Open();
                cmd = new SqlCommand(@"UPDATE JobQuotations1
                                          SET TransactionStatus = @Done
                                         WHERE TransactionID = @Tid
                                        AND
                                        TransactionNum = @num", con);

                cmd.Parameters.AddWithValue("@Done", "Done");
                cmd.Parameters.AddWithValue("@Tid", row.Cells[2].Text);
                cmd.Parameters.AddWithValue("@num", row.Cells[4].Text);


                cmd.ExecuteNonQuery();
                con.Close();
                LoadDataGrid();
            }

        }
rai nalasa
  • 849
  • 1
  • 12
  • 32

1 Answers1

0

I added this one (!chkRow.Checked) on my if statment and that all worked for me.

` foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
            if (!chkRow.Checked)
            {
                con.Open();
                cmd = new SqlCommand(@"UPDATE JobQuotations1
                                          SET TransactionStatus = @Cancel
                                         WHERE TransactionID = @Tid
                                        AND
                                        TransactionNum = @num", con);

                cmd.Parameters.AddWithValue("@Cancel", "Cancel");
                cmd.Parameters.AddWithValue("@Tid", row.Cells[2].Text);
                cmd.Parameters.AddWithValue("@num", row.Cells[4].Text);


                cmd.ExecuteNonQuery();
                con.Close();

                LoadDataGrid();
            }

        }`
rai nalasa
  • 849
  • 1
  • 12
  • 32