I've the following problem: I have a list "lst" of "Person" objects, and I put them in a DataGridView using a Dataview object ( I need it for filters )
DataTable dt = Request.ListToDataTable(lst);
dw = new DataView(dt);
dw.Sort = "age ASC";
dataGridView1.DataSource = dw;
When I click a button, I need to get the value of a field of the Person class that I put in a hidden column, relative to the selected row. To do that, I use :
Person val = dataGridView1.SelectedRows[0].DataBoundItem as Person;
Debug.WriteLine(val.id);
but when I run the program, the result is a crash, probably because the bound item is not a Person object but a DataTable element. Can somebody point me out how can I get that element? If the colum wasn't hidden it would have been easy, but this way I can't figure out how to obtain it! Thanks to everybody