I'm trying to use checkbox to remove items from a gridview but I had this and removes every item.
DataTable data = (DataTable)(GridView2.DataSource);
data.Rows.RemoveAt(GridView2.Rows.Count - 1);
data.AcceptChanges();
GridView2.DataSource = dt;
GridView2.DataBind();
Then I'm trying this
for (int i = GridView2.SelectedRow.Count - 1; -1 < i; i--)
{
object objChecked = GridView2.SelectedRow[i].Cells[0].Value;
if ((objChecked != null) && !(bool)objChecked)
{
GridView2.Rows.RemoveAt(i);
}
}
These are the errors I'm getting
- Operator '-' cannot be applied to operands of type 'method group' and 'int'
- Cannot apply indexing with [] to an expression of type '
- GridViewRowCollection' does not contain a definition for 'RemoveAt'
and no extension method 'RemoveAt' accepting a first argument of type 'GridViewRowCollection' could be found(are you missing a using directive or an assembly reference?)