title: How to add button to GridView bound to Datatable ASP.Net
body: <p>I have a GridView in in my webform. I set the data source as a DataTable, and bind it. When I tried adding an edit button by selecting "Enable edit/update/delete", it wasn't showing up.</p>
  
  <p>But, I managed to show the button manually. On button click, how do I get the first cell value of the row, of which the button is clicked ?</p>
  
  <p>My GridView</p>
  
  <pre><code>&lt;asp:GridView ID="SOGridView" runat="server" ShowHeader="False" 
              onrowdatabound="SOGridView_RowDataBound" onrowcommand="SOGridView_RowCommand"&gt;
          &lt;Columns&gt;
          &lt;asp:TemplateField HeaderText="Actions"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Button ID="btnAddNewSO" runat="server"   CommandName="Select" height="40px" 
                                  Text="Add" Width="75px" onclick="btnAddNewSO_Click" /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;&lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>On Button Click,</p>
  
  <pre><code>SOGridView.DataSource = dt;
  SOGridView.DataBind();
  </code></pre>
  
  <p>MY DATA TABLE</p>
  
  <pre><code>    DataTable dt = new DataTable();
  dt.Columns.Add(new DataColumn("Col1", typeof(string)));
  dt.Columns.Add(new DataColumn("Col2", typeof(string)));
  dt.Columns.Add(new DataColumn("Col3", typeof(string)));
  dt.Columns.Add(new DataColumn("Col4", typeof(string)));
  dt.Columns.Add(new DataColumn("Col5", typeof(string)));
  dt.Columns.Add(new DataColumn("Col6", typeof(string)));
  dt.Columns.Add(new DataColumn("Col7", typeof(string)));
  </code></pre>
  
  <p>On Button Click in the page,</p>
  
  <pre><code>    DataRow dr = dt.NewRow();
  dr["Col1"] = ddlitemcategory.SelectedValue;
  dr["Col2"] = ddlitems.SelectedValue;
  dr["Col3"] = textQty.Text;
  dr["Col4"] = textDisc.Text;
  dr["Col5"] = textAmount.Text;
  dr["Col6"] = textPDeliveryDate.Text;
  dr["Col7"] = textPShipmentDate.Text;
  dt.Rows.Add(dr);
  
  SOGridView.DataSource = dt;
  SOGridView.DataBind();
  </code></pre>