# Web Development > ASP.NET Adding new row to DataGrid

## riswadkarharshad

Hi,

Is it possible to add new row to a datagrid control once it is bound to the data source?

If so, can anyone tell me how to do it?

Thanks,

----------


## Siva_Tech

Hi,
 Its possible to add a row...
U create a datatable.let it be DtTable.
I hope u use a dataset let it be DtSet.
Let the datagrid be DgDetails

*then use this code on click of the add button*
     DtTable = DtSet.Tables["Your Table Name"];
     DtTable.Rows.Add(DtTable.NewRow());
     DgDetails.DataSource = DtTable;
     DgDetails.DataBind();

*The concept is:*
      1) Create a datatable and bind the dataset
      2) Add a new row to the datatable
      3) Then bind the dataTable to the datagrid.

Hope u got it???

Cheers
----------
Siva
-----------
No one is born Genius

----------


## Kingsley

But some error occurs...line no:29

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 27:     {
Line 28:         table = ds.Tables["Customer"];
Line 29:         table.Rows.Add(table.NewRow());
Line 30:         dgrid.DataSource = table;
Line 31:         dgrid.DataBind();

----------

