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();
}
To clear GridView assign null to the GridView datasource.
Clear the GridSet the GridControl. DataSource property to null (Nothing in VB.NET) and call the View's Columns. Clear() method.
The DataGrid and the GridView controls have different event models. The DataGrid control raises single events for operations, while the GridView control is capable of both pre-operation and post-operation events. The GridView control supports the Sorting event that occurs when a field is sorted.
The DataGrid control provides a flexible way to display a collection of data in rows and columns. The DataGrid includes built-in column types and a template column for hosting custom content. The built-in row type includes a drop-down details section that you can use to display additional content below the cell values.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With