How to modify .NET DataGrid
Hi
I am having a problem with DataGrid display and wonder if anyone could help me . I have a datagrid where I am importing data from database table ( SQL Server 2000 ) . My goal is to to let the user import the data from the database table and add more row to the grid and save the information back to the database . In other word bring the data to the datagrid from the database and add more data to the database by adding new rows and save all the information back to the database . Presently I can import the data from the database to the datagrid but I can not add new rows to the datagrid . How do I do that . Presently the datagrid is not updatable and only showing the data that I have imported from the database . Please help
Thanks
# 1 Re: How to modify .NET DataGrid
You cannot add a row to your datagrid when your datagrid is bound to a datasource.
You can add textboxes and a button "add" before your datagrid to add data to database. For example : Your datagrid has 3 cols : name, address, phone. You can add 3 textboxes name : name, address, phone and a button "add" before your datagrid. When your user want to add data, they fill data in 3 textboxes and click add, a postback event occur, data will be inserted into database. In page-load you get data from database and fill in datagrid.
Hope this can help you.
# 2 Re: How to modify .NET DataGrid
Hi
Once you have bound the grid to the data from the database, and you have an event say a button click for add row from the user , You can use the Datatable.NewRow method to obtain a datarow add it to the datatable , then bind the grid again and when binding the grid change the edititemindex to the index of the row you added
That should help