title: ASP.NET C# Code button in gridview
body: <p>Hi all I have a GridView (GridView1) I have added a column and insert a button:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
              AutoGenerateColumns="False" DataSourceID="ObjectDataSource2" 
              onselectedindexchanged="GridView1_SelectedIndexChanged" Width="798px"&gt;
              &lt;Columns&gt;
                  .....
                  &lt;asp:ButtonField ButtonType="Button" CommandName="cmdFlag" Text="Flag" /&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Basically on click of the button I want to run a SQL Update but cant seem to click the button to enter C# and add the query. I can get in the C# for the page but unsure what to write for the method. </p>
  
  <p>Heres the C# Code:</p>
  
  <pre><code> void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          if (e.CommandName == "cmdFlag")
          {
          con.Open();
  
          cmd = new SqlCommand("UPDATE Comments SET Flagged = '" + "Yes" + "'", con); 
  
          cmd.ExecuteNonQuery();
  
  
          }
  
      }
  </code></pre>
  
  <p>Its doing nothing though. Basically I need it to look at the row and if the flagged button is clicked, update the comment to "Yes" under flagged.</p>