title: ASP.NET: How to get values from a selected row from GridView control
body: <p>I have added a GridView control on my ASP.net webpage and data bound it to a <code>List&lt;&gt;</code> the list contains a collection of a simple custom objects which is defined as:</p>
  
  <pre><code>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; }
  }
  </code></pre>
  
  <p>I have set <code>AutoGenerateSelectButton</code> to true and and attached an event handler to the <code>SelectedIndexChanged</code> event. I can see my event handler fires and I can get the selected row index by using <code>MyGridView.SelectedIndex</code>.</p>
  
  <p><strong>My question is</strong>: how do I use the selected row index to get the PersonId for the selected record?</p>
  
  <p>I thought <code>MyGridView.Rows[MyGridView.SelectedIndex].Cells[0]</code> would do it but it doesn't because MyGridView.Rows.Count is 0.</p>
  
  <p>TIA</p>