for (int i = 1; i <= dataGridView1.Rows.Count; i++) { if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[1].Value)==true) { dataGridView1.Rows.RemoveAt ( i); } }
dataGridView1.Rows[1].Cells[1].Value =null //if I check 1st Row
protected void btnMultipleRowDelete_Click(object sender, EventArgs e) { // Looping through all the rows in the GridView foreach (GridViewRow row in GridView1.Rows) { CheckBox checkbox = (CheckBox)row.FindControl("cbRows"); //Check if the checkbox is checked. //value in the HtmlInputCheckBox's Value property is set as the //value of the delete command's parameter. if (checkbox.Checked) { // Retreive the Employee ID int employeeID = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value); // Pass the value of the selected Employye ID to the Delete //command. SqlDataSource1.DeleteParameters["EmployeeID"].DefaultValue = employeeID.ToString(); SqlDataSource1.Delete(); } } }
List<int> indexes = new List<int>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value != null) if ((bool)row.Cells[1].Value) indexes.Add(row.Index); } foreach (int index in indexes) dataGridView1.RemoveAt(index);</int></int>
for (int i = 1; i <= dataGridView1.Rows.Count; i++)
for (int i = 0; i < dataGridView1.Rows.Count; i++)
for (int i = 0; i < dataGridView1.Rows.Count; i++) { //Get the appropriate cell using index, name or whatever and cast to DataGridViewCheckBoxCell DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[1]; //Compare to the true value because Value isn't boolean if (cell.Value == cell.TrueValue) { //The value is true dataGridView1.Rows.RemoveAt(i); i = ((i - 1) < 0) ? 0 : (i - 1); //Since the Rows count decremented by 1. //So, decrement the loop counter by 1 } }
if (((CheckBox)(dataGridView1.Rows[i].Cells[1].FindControl("checkBoxName"))).Checked == true) { dataGridView1.Rows.RemoveAt(i); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)