How to clear the actual data source and how to clear what is shown in the grid.Are you trying to clear the actual data source, or trying to clear the data grid?
DELETE
commands to delete the rows from the table(s), and then to let the data grid show that table is now empty, you would do the same query into a data table and then bind that to the data grid.DataSource
property to null and then do the binding and it would also clear the data grid. I just can't recall whether those were production versions or beta versions.To clear the actual data source, you would do the appropriate SQLDELETE
commands to delete the rows from the table(s), and then to let the data grid show that table is now empty, you would do the same query into a data table and then bind that to the data grid.
To clear the grid view, just bind an empty data table. As I recall some versions of the WebForms also let you set theDataSource
property to null and then do the binding and it would also clear the data grid. I just can't recall whether those were production versions or beta versions.
DataSource
property to null and then do the binding and it would also clear the data grid.DataTable dt = null;
GridView.DataSource = dt;
GridView.DataBind();
Try it out and see what happens. As I said some versions of WebForms supported just assigning null and invoking the binding, but I don't recall exactly what versions and whether they were actually released to production, or if they were just beta versions of the .NET Framework many years ago.