删除取消选中datagrid上的值

时间:2016-06-01 22:31:01

标签: c# asp.net gridview datagrid

我想使用取消按钮删除我在数据网格上取消选中的所有值。我知道如何使用已检查的值执行此操作但是如何在未检查的行中执行此操作?

这是我使用按钮继续

的代码
  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();
            }

        }

1 个答案:

答案 0 :(得分:0)

我在if语句中添加了(!chkRow.Checked),并且这一切都对我有用。

` 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();
            }

        }`