How to clear the datagrid

calvin

Regular
Joined
Nov 6, 2003
Messages
71
Hi,

I do a textbox to collect data and binding to datagrid(use arraylist to hold data).
When user click the submit button, all the data in arraylist will be add to database.

Then, if I try to add data to datagrid, the previous "record" still remain in datagrid. I would like to know how to clear the datagrid.

Is anyknow could give me some idea and help will more appreciate.

Calvin :)
 
Did you try clearing the array that is bound to the datagrid as part of the submit event?
 
How to refresh(clear) datagrid binding with DataTable?

Problem has been solved, the approach on the below will refresh the arraylist.

DataGrid1.DataSource = (New ArrayList)
DataGrid1.DataBind()

But how about refreshing the DataTable binding to datagrid? Any idea?

Calvin :)
 
If I understand correctly the data entered within a text box is used to increment an array list which also fills the datagrid. When all of the required data is entered, as validated by the datagrid content, the OnClick event of the submit button is used to update some database. Therefore, there is 2 unique things going on. I don't understand what you mean by DataTable. I would try to approach the OnClick event like;

Define database connection
Define data adapter
Define dataset
Use the fill method of the adapter to populate dataset
Create CommandBuilder object
Define a new row based on the data in the array
Use the update method of the adapter to add new record to database
 
Back
Top