title: asp.net (C#): get value of a non-displayed field from a gridview selection
body: <p>I have a GridView control bound to an ObjectDataSource which returns a list of objects that look like this:</p>
  
  <pre><code>public class X {
      public string DisplayName {
          get;
      }
      public string Guid {
          get;
      }
  }
  </code></pre>
  
  <p>I don't want to show the <code>Guid</code> property in the GridView, but I need to retrieve it when an object is selected.<br>
  I could not find a "DataValueField" property, like for the ListBox control.<br>
  As a workaround, I tried to set <code>Visible=false</code> for the column bound to the Guid property and get the cell text from the <code>Row</code> object in the <code>SelectedIndexChanged</code> method:</p>
  
  <pre><code>protected void GridView1_SelectedIndexChanged(object sender,EventArgs e){
      GridViewRow row = GridView1.SelectedRow;
      string id = row.Cells[2].Text; // empty
  }
  </code></pre>
  
  <p>But this does not work - apparently if the column is not visible its Text property is left empty.  </p>
  
  <p>How can I get the Guid of the selected object while showing only the DisplayName?</p>