title: Accessing the data or dataItem used to bind a gridview
body: <p>I have a gridview for which I programmatically set the datasource and databind it to a collection of objects. For each row that is created I then use different methods in the  fields to extract the relevant information from the object like this one:</p>
  <pre><code>&lt;asp:TemplateField HeaderText=&quot;Aliases&quot;&gt;
  &lt;ItemTemplate&gt;
  &lt;%# ( (MyItem)Container.DataItem).Aliases.ToString() %&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  <p>My problem is that in the <code>OnRowDeleting</code> method I would preferably like to be able to access that <code>DataItem</code> using e g <code>MyGridView.Rows[e.RowIndex].DataItem</code> or in other way. But I can’t find how to configure the <code>Gridview</code> to retain the <code>DataItem</code>. <strong>Is it possible to access the <code>DataItem</code> used and how would I configure it to do it?</strong> If that’s not possible can I access the values that are bind by the methods? Or do I have to go with plan B and rewrite the datasource object collection to a datatable and then use datakeysnames?</p>