Reputation: 10134
how do i clear the contents of a data grid that's bound to an list of generic objects?
private void BindGrid(ReportWizardCriteria criteria)
{
gvCriteria.DataSource = criteria.CriteriaList;
gvCriteria.DataBind();
}
Upvotes: 6
Views: 11860
Reputation: 4619
try,
gvCriteria.Items.Clear();
or,
gvCriteria.DataSource = null;
gvCriteria.DataBind();
Upvotes: 1
Reputation: 21171
You can set the .DataSource property to null. That ought to do it.
gvCriteria.DataSource = null;
gvCriteria.DataBind();
Upvotes: 1
Reputation: 63126
gvCriteria.DataSource = null;
gvCriteria.DataBind();
Or you can bind it to an empty collection as well, similar to this
gvCriteria.DataSource = new List<MyObject>();
gvCriteria.DataBind();
For some people the second one is a bit "easier" to understand
Upvotes: 14