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.DataSour开发者_StackOverflow社区ce = criteria.CriteriaList;
gvCriteria.DataBind();
}
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
You can set the .DataSource property to null. That ought to do it.
gvCriteria.DataSource = null;
gvCriteria.DataBind();
try,
gvCriteria.Items.Clear();
or,
gvCriteria.DataSource = null;
gvCriteria.DataBind();
精彩评论