title: imagebutton in gridview...can't get correct row key
body: <p>I'm developing a C# asp.net 4.5 web page.</p>
  
  <p>I have a GridView to which I've bound the results of a linq query using BoundFields and TemplateFields.  All that works fine.  </p>
  
  <p>But I also have an ImageButton within a TemplateField in each row. I need to have that button run some code using the data key of the row the ImageButton was on.</p>
  
  <p>I've tried using the DataKeyNames but when I debug the DataKey value is always null.</p>
  
  <p>I've also tried an OnClick method but I don't know how to retrieve the key from the GridView.</p>
  
  <p>EDIT: Here's the GridView code</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderColor="#336699" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" Font-Names="Verdana" Font-Size="10pt"OnRowCreated="GridView1_RowCreated" DataKeyNames="titleid" EnablePersistedSelection="True" EnableViewState="False" &gt;
  </code></pre>
  
  <p>Here's the ImageButton TemplateField:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText ="Save"&gt;
       &lt;ItemTemplate&gt;
            &lt;asp:ImageButton ID ="btnSave" runat="server" OnClick="btnSave_Click"CommandName="SaveTitle" ImageUrl="~/images/download.jpg" CommandArgument='&lt;%# Container.DisplayIndex %&gt;' /&gt;
       &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>