title: GridView with SqlDataSource: Update does not work
body: <p>I'm using the auto generated edit feature of GridView. The edit button appears, clicking it enters edit mode but making changes and clicking update does nothing (that I can tell). The database does not update. Through testing it seems that OnRowEditing triggers but OnRowUpdating does not. INSERT, SELECT and DELETE all work perfectly. I have tested my UpdateCommand on the SQL database directly and it works as intended. </p>
  
  <p>Why does this not work? I've been searching for answers for days now.</p>
  
  <p>Here is the full code in its current state:</p>
  
  <pre><code>&lt;%@ Page Language="C# " AutoEventWireup="true"%&gt;
  &lt;%@Import Namespace="System.Data" %&gt;
  &lt;%@Import Namespace="System.Data.Common" %&gt;
  &lt;%@Import Namespace="System.Data.SqlClient" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;script runat="server"&gt;
      private void InsertDomain(Object source, EventArgs e)
      {
          SqlDataSource2.Insert();
      }
      private void OnDomainDeleted(Object source, SqlDataSourceStatusEventArgs e)
      {
          Label1.Text = e.AffectedRows + " row(s) were deleted";
      }
      protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
      {
          int x = 5;
      }
      protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {
          bool x = e.Cancel;
      }
      protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
      {
          int x = e.AffectedRows;
      }
  &lt;/script&gt;
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Domain Manager&lt;/title&gt;
      &lt;link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' /&gt;
      &lt;link href="~/Content/Site.css" rel="stylesheet" type="text/css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;asp:Label
          id="Label1"
          runat="server"
          forecolor="Red" /&gt;
  
      &lt;h1&gt;Godaddy&lt;/h1&gt;
      &lt;form id="form1" runat="server"&gt;
  
          &lt;asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              ConnectionString="&lt;%$ ConnectionStrings:SQLconnect %&gt;"
              SelectCommand="SELECT DomainName,InUse FROM DomainList"
              UpdateCommandType="Text"
              UpdateCommand="UPDATE DomainList SET InUse=@InUse WHERE (DomainName=@DomainName)"
              DeleteCommand="DELETE FROM DomainList WHERE DomainName=@DomainName"
              OnDeleted="OnDomainDeleted"&gt;
              &lt;UpdateParameters&gt;
                  &lt;asp:Parameter Name="DomainName" Type="String" /&gt;
                  &lt;asp:Parameter Name="InUse" Type="String" /&gt;
              &lt;/UpdateParameters&gt;
          &lt;/asp:SqlDataSource&gt;
  
          &lt;asp:GridView
              id="GridView1"
              runat="server"
              AutoGenerateColumns="false"
              DataKeyNames="DomainName"
              AutoGenerateEditButton="true"
              AutoGenerateDeleteButton="true"
              EnableViewState="true"
              ViewStateMode="Enabled"
              DataSourceID="SqlDataSource1"
              AllowSorting="true"
              OnRowEditing="GridView1_RowEditing"
              OnRowUpdating="GridView1_RowUpdating"
              OnRowUpdated="GridView1_RowUpdated"&gt;
              &lt;rowstyle backcolor="LightCyan"  
                     forecolor="Black" /&gt;
              &lt;alternatingrowstyle backcolor="PaleTurquoise"  
                    forecolor="Black" /&gt;
              &lt;columns&gt;
                  &lt;asp:BoundField HeaderText="Domain Name" DataField="DomainName" ReadOnly="true" SortExpression="DomainName" /&gt;
                  &lt;asp:BoundField HeaderText="In Use" DataField="InUse" SortExpression="InUse" /&gt;
                  &lt;%--&lt;asp:BoundField HeaderText="Domain Cost" DataField="DomainCost" /&gt;
                  &lt;asp:BoundField HeaderText="TLD" DataField="TLD" /&gt;
                  &lt;asp:BoundField HeaderText="Registrar" DataField="Registrar" /&gt;
                  &lt;asp:BoundField HeaderText="Expiration Date" DataField="ExpirationDate" /&gt;
                  &lt;asp:BoundField HeaderText="Status" DataField="Status" /&gt;
                  &lt;asp:BoundField HeaderText="Privacy" DataField="Privacy" /&gt;
                  &lt;asp:BoundField HeaderText="Forwarding URL" DataField="ForwardingURL" /&gt;
                  &lt;asp:BoundField HeaderText="Notes" DataField="Notes" /&gt;
                  &lt;asp:BoundField HeaderText="Department/Program" DataField="DepartmentProgram" /&gt;
                  &lt;asp:BoundField HeaderText="Program Contact" DataField="ProgramContact" /&gt;--%&gt;
              &lt;/columns&gt;
          &lt;/asp:GridView&gt;
  
          &lt;hr /&gt;
  
          &lt;asp:SqlDataSource
              id="SqlDataSource2"
              runat="server"
              ConnectionString="&lt;%$ ConnectionStrings:SQLconnect %&gt;"
              SelectCommand="SELECT * FROM DomainList"
              InsertCommand="INSERT INTO DomainList (DomainName,InUse,DomainCost,TLD,Registrar,ExpirationDate,Status, 
                                      Privacy,ForwardingURL,Notes,DepartmentProgram,ProgramContact) VALUES (@DName,@IUse,@DCost,
                                      @TLD,@Registrar,@ExDate,@Status,@Privacy,@FURL,@Notes,@Dept,@PContact)" &gt;
                  &lt;insertparameters&gt;
                      &lt;asp:FormParameter Name="DName" FormField="DomainNameBox" /&gt;
                      &lt;asp:FormParameter Name="IUse" FormField="InUseBox" /&gt;
                      &lt;asp:FormParameter Name="DCost" FormField="DomainCostBox" /&gt;
                      &lt;asp:FormParameter Name="TLD" FormField="TLDBox" /&gt;
                      &lt;asp:FormParameter Name="Registrar" FormField="RegistrarBox" /&gt;
                      &lt;asp:FormParameter Name="ExDate" FormField="ExDateBox" /&gt;
                      &lt;asp:FormParameter Name="Status" FormField="StatusBox" /&gt;
                      &lt;asp:FormParameter Name="Privacy" FormField="PrivacyBox" /&gt;
                      &lt;asp:FormParameter Name="FURL" FormField="FURLBox" /&gt;
                      &lt;asp:FormParameter Name="Notes" FormField="NotesBox" /&gt;
                      &lt;asp:FormParameter Name="Dept" FormField="DeptBox" /&gt;
                      &lt;asp:FormParameter Name="PContact" FormField="PContactBox" /&gt;
                  &lt;/insertparameters&gt;
          &lt;/asp:SqlDataSource&gt;
  
          &lt;h1&gt;Create New Godaddy Domain: &lt;/h1&gt;
  
          &lt;br /&gt;Domain Name: &lt;asp:TextBox
              id="DomainNameBox"
              runat="server" /&gt;
  
          &lt;asp:RequiredFieldValidator
              id="RequiredFieldValidator1"
              runat="server"
              ControlToValidate="DomainNameBox"
              Display="Static"
              ErrorMessage="You must enter a domain name" /&gt;
  
          &lt;br /&gt;In Use? (yes/no): &lt;asp:TextBox
              id="InUseBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Cost: &lt;asp:TextBox
              id="DomainCostBox"
              runat="server" /&gt;
  
          &lt;br /&gt;TLD: &lt;asp:TextBox
              id="TLDBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Registrar: &lt;asp:TextBox
              id="RegistrarBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Expiration Date: &lt;asp:TextBox
              id="ExDateBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Status: &lt;asp:TextBox
              id="StatusBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Privacy: &lt;asp:TextBox
              id="PrivacyBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Forwarding URL: &lt;asp:TextBox
              id="FURLBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Notes: &lt;asp:TextBox
              id="NotesBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Department: &lt;asp:TextBox
              id="DeptBox"
              runat="server" /&gt;
  
          &lt;br /&gt;Program Contact: &lt;asp:TextBox
              id="PContactBox"
              runat="server" /&gt;
  
          &lt;br /&gt;&lt;asp:Button
              id="Button1"
              runat="server"
              text="Create New Domain"
              onclick="InsertDomain" /&gt;
  
          &lt;hr /&gt;
  
          &lt;h1&gt;Network Solutions&lt;/h1&gt;
  
          &lt;asp:GridView
              id="GridView2"
              runat="server"
              AutoGenerateColumns="false"
              AutoGenerateEditButton="true"
              DataKeyNames="DomainName"
              DataSourceID="SqlDataSource3"&gt;
              &lt;rowstyle backcolor="LightCyan"  
                     forecolor="Black"
                     /&gt;
                  &lt;alternatingrowstyle backcolor="PaleTurquoise"  
                    forecolor="Black"
                    /&gt;
              &lt;columns&gt;
                  &lt;asp:BoundField HeaderText="Domain Name" DataField="DomainName" ReadOnly="true" /&gt;
                  &lt;asp:BoundField HeaderText="Account" DataField="AccountNo" /&gt;
                  &lt;asp:BoundField HeaderText="Points To" DataField="PointsTo" /&gt;
                  &lt;asp:BoundField HeaderText="Folder" DataField="Folder" /&gt;
                  &lt;asp:BoundField HeaderText="Auto Renew" DataField="AutoRenew" /&gt;
                  &lt;asp:BoundField HeaderText="Expiration Date" DataField="ExpirationDate" /&gt;
                  &lt;asp:BoundField HeaderText="WHOIS Admin" DataField="AdminContact" /&gt;
                  &lt;asp:BoundField HeaderText="WHOIS Tech" DataField="TechContact" /&gt;
                  &lt;asp:BoundField HeaderText="Account Holder" DataField="AccountHolder" /&gt;
                  &lt;asp:BoundField HeaderText="Private" DataField="Private" /&gt;
              &lt;/columns&gt;
          &lt;/asp:GridView&gt;
  
          &lt;asp:SqlDataSource 
              id="SqlDataSource3"
              runat="server"
              DataSourceMode="DataReader"
              ConnectionString="&lt;%$ ConnectionStrings:SQLconnect%&gt;"
              SelectCommand="SELECT DomainName,AccountNo,PointsTo,Private,Folder,AutoRenew,ExpirationDate, 
                                  AdminContact,TechContact,AccountHolder FROM NetworkSolutions"
              UpdateCommand="UPDATE NetworkSolutions SET AccountNo=@AccountNo,PointsTo=@PointsTo,Private=@Private,Folder=@Folder,AutoRenew=@AutoRenew,ExpirationDate=@ExpirationDate,
                              AdminContact=@AdminContact,TechContact=@TechContact,AccountHolder=@AccountHolder WHERE (DomainName=@DomainName)"&gt;
          &lt;/asp:SqlDataSource&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>SOLUTION: I had a function <code>InsertDomain</code> that seemed to be catching the updates from the GridViews. Solution required setting a <code>ValidationGroup</code> to restrict that validation from affecting the whole page.</p>