kacalapy
kacalapy

Reputation: 10134

How to clear an ASP.NET datagrid?

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

Answers (3)

Illuminati
Illuminati

Reputation: 4619

try,

gvCriteria.Items.Clear();

or,

gvCriteria.DataSource = null;

gvCriteria.DataBind();

Upvotes: 1

Kevin Tighe
Kevin Tighe

Reputation: 21171

You can set the .DataSource property to null. That ought to do it.

gvCriteria.DataSource = null;
gvCriteria.DataBind();

Upvotes: 1

Mitchel Sellers
Mitchel Sellers

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

Related Questions