title: Add ID to GridView Row
body: <p>How to add ID to GridView rows (IDs should be rendered)?</p>
  
  <p>I am using .NET (C#). I have GridView control.</p>
  
  <p>I have some javascript functions that are manipulating table rows, but it is necessary to have IDs for those rows:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr id=1&gt; ...  
      &lt;tr id=2&gt; ...  //id should come from database
  ..
  </code></pre>
  
  <p>My GridView is genereted from Data from DataBase. It is important not to have FAKE ROW IDS, but really row ids from DB (there are some ajax javascript function that updates DB based on those IDs and user manipulations with table).</p>
  
  <p>Part of my GridView is the following:</p>
  
  <pre><code>  &lt;asp:GridView ID="grdNews" runat="server" BorderStyle="None" RowStyle-BorderStyle="None"
                  GridLines="None" CssClass="table" Style="white-space: nowrap" AutoGenerateColumns="False"
                  DataKeyNames="ID" AllowSorting="True" AllowPaging="true" OnSorting="grdNews_Sorting" OnRowDataBound="grdNews_RowDataBound"&gt;
                  &lt;RowStyle BorderStyle="None" /&gt;
                  &lt;HeaderStyle CssClass="nodrag" /&gt;
                  &lt;Columns&gt;
                  ....
  </code></pre>
  
  <p>I have tried the following:</p>
  
  <pre><code> protected void grdNews_RowDataBound(object sender, GridViewRowEventArgs e)
  {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           e.Row.ID = grdNews.DataKeys[e.Row.RowIndex].Value.ToString();
       }
  }
  </code></pre>
  
  <p>This gives e.Row.ID the correct value, but this doesn't render this ID.</p>
  
  <p>So, how to render IDs from DataBase for Rows in GridView?</p>