title: Get DataKey values in GridView RowCommand
body: <p>I have a <code>GridView</code> with an associated <code>DataKey</code>, which is the item ID.
  How do I retrieve that value inside the <code>RowCommand</code> event?</p>
  
  <p>This seems to work, but I don't like the cast to <code>LinkButton</code> (what if some other command is firing the event?), and I'm not too confident about the <code>NamingContainer</code> bit.</p>
  
  <pre><code>LinkButton lb = (LinkButton)e.CommandSource;
  GridViewRow gvr = (GridViewRow)lb.NamingContainer;
  int id = (int)grid.DataKeys[gvr.RowIndex].Value;
  </code></pre>
  
  <p>I'm aware that I could instead pass that ID as the <code>CommandArgument</code>, but I chose to use <code>DataKey</code> to give me more flexibility.</p>
  
  <p>I'm also aware that it's possible to use a hidden field for the ID, but I consider that a hack that I don't want to use.</p>