How to add rows to GridView by clicking on a button?
Posted on 2010-08-24
I'm developing a sharepoint custom field. In my class, which inherits from BaseFieldControl class, and particularly in the method "CreateChildControls", I created a DataTable, and I inserted two rows into it.
Also, I have a GridView with 4 columns. The dataSource for this GridView is the above DataTable.
Then, I have 4 text box fields and a button "Add".
When clicking on "Add" button, I create a new row with the values entered in the text box fields, then I add this row to the Datatable, then I rebind the datatable to the GridView as a DataSource.
So the new row appears in the GridView.
But , if I fill in again the 4 fields and click on "Add", I got that the new row replaces, in the GridView, the row that I have added when I clicked on the "Add" button for the first time.
While, the required result is to see the second row with the first one in the GridView.
And, if I count the number of rows in the GridView, I found that the inserted rows by clicking on "Add" button are not considered.
So, how can I resolve it?