I have added a GridView control on my ASP.net webpage and data bound it to a List<>
the list contains a collection of a simple custom objects which is defined as:
public class PersonRecord
{
public int PersonId { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Notes { get; set; }
}
I have set AutoGenerateSelectButton
to true and and attached an event handler to the SelectedIndexChanged
event. I can see my event handler fires and I can get the selected row index by using MyGridView.SelectedIndex
.
My question is: how do I use the selected row index to get the PersonId for the selected record?
I thought MyGridView.Rows[MyGridView.SelectedIndex].Cells[0]
would do it but it doesn't because MyGridView.Rows.Count is 0.
TIA