title: How to access a selected Boundfield value from a GridView in code-behind
body: <p>I have seen similar questions but none of the answers helped me to workout this problem.
  I have GridView with a ReadOnly field as follow.</p>
  
  <p><strong>GridView:</strong></p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                AutoGenerateColumns="False" DataKeyNames="projectID" 
                DataSourceID="SqlDataSource1" 
                EmptyDataText="There are no data records to display." 
                PageSize="5" OnRowUpdating="GridView1_RowUpdating"&gt;
    &lt;Columns&gt;
      &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True"/&gt;
      &lt;asp:BoundField DataField="prID" HeaderText="prID" SortExpression="prID"/&gt;
      &lt;asp:BoundField DataField="projectName" HeaderText="projectName" 
                      SortExpression="projectName" /&gt;
      &lt;asp:BoundField DataField="projectType" HeaderText="projectType" 
                      SortExpression="projectType" /&gt;
    &lt;/Columns&gt;
    &lt;EditRowStyle CssClass="GridViewEditRow"/&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>as you can see the <code>prID</code> BoundField has <code>Readonly=True</code> attribute.
  I'm trying to get the value of the <code>prID</code> in code-behind when user is updating the other fields in the row.</p>
  
  <p><strong>code-behind:</strong></p>
  
  <pre><code>protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
  
      GridViewRow row = GridView1.Rows[e.RowIndex];
  
      String d1 = ((TextBox)(row.Cells[2].Controls[0])).Text;
      String d2 = ((TextBox)(row.Cells[3].Controls[0])).Text;
  
      // this only works while the field is not readonly      
      string prIDUpdate = ((TextBox)(row.Cells[1].Controls[0])).Text; 
  
  }
  </code></pre>
  
  <p><strong>Note:</strong> I have tried using <code>GridView1.DataKeys[e.RowIndex]</code> and also <code>onRowDataBound</code> an d setting the BoundField ready only in code-behind but I haven't been able to get results</p>
  
  <p>Thanks in advance!</p>