How to clear a datagrid on a button click?

Showing Answers 1 - 3 of 3 Answers

Alex

  • Dec 14th, 2005
 

Hi,

You need to Clear the DataSource of the dadaGrid.

So try this:

dataSet1.Clear();

dataGrid1.DataSource = dataSet1.TableNameHere.DefaultView;

 or

C#: dataGrid1.DataSource = null;

VB: dataGrid1.DataSource = nothing

 

  Was this answer useful?  Yes

darkdusky

  • Sep 26th, 2008
 

Easy way to clear a grid without creating new dataset, but this method loses headers also.

datagrid1.datasource=""
datagrid1.Databind()

  Was this answer useful?  Yes

Lets say your grid id is dgCompliance, so to make it empty just write following code in vb.net:

dgCompliance.DataSource = Nothing

dgCompliance.DataBind()

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions