dgvGridView1.DataSource=null
The above code line clearing all records with the headers as well. How do I clear the rows without clearing the header names in the gridview.
Solution
It is a pretty simple and straightforward answer to clear all the records in a GridView without clearing the header by using data table Clear() method.
DataTable dt = (DataTable)dgvGridView1.DataSource;
dt.Clear();
dgvGridView1.DataSource = dt;
Conclusion
Casting the Gridview datasource as a data table and clear the datatable and assign the cleared data table object to the gridview data source again will solve the problem, we hope you find them helpful.