Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
}
like image 855
kacalapy Avatar asked Nov 18 '10 20:11

kacalapy


People also ask

How to clear datagridview in asp net?

To clear GridView assign null to the GridView datasource.

How to clear GridView in c#?

Clear the GridSet the GridControl. DataSource property to null (Nothing in VB.NET) and call the View's Columns. Clear() method.

What is the difference between DataGrid and GridView?

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.

What is DataGrid control in C#?

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.


1 Answers

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

like image 67
Mitchel Sellers Avatar answered Nov 03 '22 01:11

Mitchel Sellers