Resolved How do I clear DataSource or delete old data in DataSource?

patrick

Well-known member
Joined
Dec 5, 2021
Messages
238
Programming Experience
1-3
I am using GridView.

How do I clear DataSource or delete old data in DataSource?

Is the source below correct?

please tell me another way.


C#:
DataTable dt = null;
GridView.DataSource = dt;
 
I assume this is a related to your ASP.NET GridView question in your b other thread. Moving to ASP.NET.
 
Are you trying to clear the actual data source, or trying to clear the data grid?
 
To clear the actual data source, you would do the appropriate SQL 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.

To clear the grid view, just bind an empty data table. As I recall some versions of the WebForms also let you set the 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 SQL 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.

To clear the grid view, just bind an empty data table. As I recall some versions of the WebForms also let you set the 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.

Your Answer ) To clear the grid view, just bind an empty data table. As I recall some versions of the WebForms also let you set the DataSource property to null and then do the binding and it would also clear the data grid.

====> My Question) Are you talking about this code? Can I use this code?
C#:
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.
 
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.

thank you for your teaching.
 
Back
Top Bottom