Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to copy data from datagrid to datatable. I need to delete the selected row from datagrid, for this i am trying to copy data from datagrid to datatable and deleting the selected row from datatable and bind the datatable again to datagrid. but i am getting the object reference error on the line if(dt.rows.count). what could be the problem or is there any other easy way to remove the selected row.
dt = (DataTable)Datagrid1.DataSource;

if (dt.Rows.Count > 0)
{
   dt.Rows[2].Delete();
}
Posted
Updated 9-Oct-11 23:16pm
v3
Comments
Bala Selvanayagam 10-Oct-11 5:24am    
how do you populate the data to the data grid at the first place ? please post the code showing how you are populating the datagrid for us to come up with the suggestion

 
Share this answer
 
Actually dt is null after this
dt = (DataTable)Datagrid1.DataSource;

Thats why you are getting this error.
 
Share this answer
 
How can i copy Datagrid values to datatable?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900