views:

208

answers:

2

I have a GridView, I bind it to ObjectDataSource. ObjectDataSource takes data from a database's table. Each row in table has unique ID.

I have a button in each row of GridView that should remove this row from database. My ObjectDataSource returns Object, this returned object contains ID (and some other information, like name, user etc.) however I do not show this ID on my grid.

Question how can I get these ID after user chooses to delete row, I need to know what I should remove.

+1  A: 

You should assign DataKeyName property of the grid view, once you do that, you can get value of your id that you have provided in .DataKey property, which is explain in detail here with source code

lakhlaniprashant.blogspot.com
+1  A: 

If you using BindingSource, than you always can get current object.

For example somewhere in mouse click handle:

var myData = (MyData)bindingSource.Current;
MyDataRepository.DeleteMyDataById(myData.Id);
Sergey Teplyakov