title: GridView OnRowUpdating does not fire due to CommandName="edit"
body: <p>I already spend 2 days trying to solve this issue but no luck on how to solve this. I have a GridView to display data from the database then it also have functionality to modify and delete. This is the current ASP code for my GridView:</p>
  
  <pre><code>&lt;asp:GridView ID="dgvSortKey" runat="server" AllowSorting="True" OnRowDataBound="gv_drb"
                  AutoGenerateColumns="False" AllowPaging="True" BackColor="White" BorderColor="#336666"
                  BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
                  Height="73px" AutoGenerateEditButton="True" OnRowEditing="dgvSortKey_RowEditing"
                  OnRowUpdating="dgvSortKey_RowUpdating" OnRowCancelingEdit="dgvSortKey_RowCancelingEdit"
                  OnSelectedIndexChanging="dgvSortKey_SelectedIndexChanging" OnPageIndexChanged="dgvSortKey_PageIndexChanged"
                  OnPageIndexChanging="dgvSortKey_PageIndexChanging" OnRowCommand="dgvSortKey_RowCommand"
                  OnRowDeleted="dgvSortKey_RowDeleted" OnRowUpdated="dgvSortKey_RowUpdated" Width="561px"
                  PageSize="15" DataKeyNames="KeyCode,KeyDescription"&gt;
                  &lt;FooterStyle BackColor="White" ForeColor="#333333" /&gt;
                  &lt;RowStyle BackColor="White" ForeColor="#333333" /&gt;
                  &lt;PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /&gt;
                  &lt;SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /&gt;
                  &lt;HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" /&gt;
                  &lt;AlternatingRowStyle BackColor="LightCyan" /&gt;
                  &lt;Columns&gt;
                      &lt;asp:TemplateField HeaderText=""&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:LinkButton ID="lnkdelete" runat="server" OnClick="lnkdelete_Click"&gt;Delete&lt;/asp:LinkButton&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Instruction Key Code"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblValKeyCode" runat="server" Text='&lt;%#System.Web.HttpUtility.HtmlEncode((string)Eval("KeyCode")) %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox ID="txtValKeyCode" runat="server" Text='&lt;%#Bind("KeyCode") %&gt;' MaxLength="10"
                                  CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="GvBorderGreen" /&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Description"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblValKeyDescription" runat="server" Text='&lt;%#System.Web.HttpUtility.HtmlEncode((string)Eval("KeyDescription")) %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox ID="txtValKeyDescription" runat="server" Text='&lt;%#Bind("KeyDescription") %&gt;'
                                  Width="300" MaxLength="20" CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;ItemStyle CssClass="GvBorderGreen" /&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>The problem is I can't update a certain record after click the Update Button, please see the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/7v5UV.png" alt="enter image description here"></p>
  
  <p>When I'm in debug mode, it does not pass on OnRowUpdating event instead it passes to OnRowEditing. One thing that it makes me surprise is that when it fires to OnRowCommand, the CommandName set to <strong><em>"Edit"</em></strong> when <strong><em>Update Button</em></strong> is clicked. Please see the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/WR2ql.png" alt="enter image description here"></p>
  
  <p>BTW this the Code Behind.</p>
  
  <pre><code>protected void dgvSortKey_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {
          //Currently Unreachable code due to unknown reason. RowUpdating not trigger even clicking Update Button in the GridView
          // this.dvDetialContent.Visible = true;
          List&lt;SqlDbParameter&gt; list = new List&lt;SqlDbParameter&gt;();
  
          TextBox txtValKeyDescription = dgvSortKey.Rows[e.RowIndex].FindControl("txtValKeyDescription") as TextBox;
          TextBox txtValKeyCode = dgvSortKey.Rows[e.RowIndex].FindControl("txtValKeyCode") as TextBox;
  
          if (string.IsNullOrEmpty(txtValKeyCode.Text) || string.IsNullOrEmpty(txtValKeyDescription.Text))
          {
              string alert = "alert('Instruction KeyCode or KeyDecription should not be empty');";
              ScriptManager.RegisterStartupScript(this, this.GetType(), "scripting", alert, true);
          }
          else
          {
              //Trace.Write("txtKeyCode", HttpUtility.HtmlDecode(txtKeyCode.Text));
              //Trace.Write("txtKeyDescription", txtKeyDescription.Text);
              //Trace.Write("txtValKeyCode", txtValKeyCode.Text);
              //Trace.Write("txtValKeyDescription", txtValKeyDescription.Text);
              list.Add(new SqlDbParameter("@oldcode", HttpUtility.HtmlDecode(txtKeyCode.Text)));
              list.Add(new SqlDbParameter("@oldname", HttpUtility.HtmlDecode(txtKeyDescription.Text)));
              list.Add(new SqlDbParameter("@newcode", HttpUtility.HtmlDecode(txtValKeyCode.Text)));
              list.Add(new SqlDbParameter("@newname", HttpUtility.HtmlDecode(txtValKeyDescription.Text)));
              try
              {
                  int result = CoreUtility.ExecuteNonQuery("update InstructionKey set KeyCode=@newcode, KeyDescription=@newname where KeyCode = @oldcode and KeyDescription = @oldname", list);
                  //Trace.Write("ResultValue", result.ToString());
              }
              catch (Exception ex)
              {
                  string alert = "alert('Instruction KeyCode should not be duplicate');";
                  ScriptManager.RegisterStartupScript(this, this.GetType(), "scripting2", alert, true);
              }
          }
  
          dgvSortKey.EditIndex = -1;
          imgbtnFilter_Click(null, null);
  
          this.txtKeyCode.Text = "";
          this.txtKeyDescription.Text = "";
  
      }
      protected void dgvSortKey_RowEditing(object sender, GridViewEditEventArgs e)
      {
          // this.dvDetialContent.Visible = true;
          //if (ViewState["updateFlag"] == null)
          //{
              //ViewState["editFlag"] = "forEdit";
              //ViewState["editIndex"] = e.NewEditIndex;
              dgvSortKey.EditIndex = e.NewEditIndex;
              Label lblValKeyDescription = dgvSortKey.Rows[e.NewEditIndex].FindControl("lblValKeyDescription") as Label;
              Label lblValKeyCode = dgvSortKey.Rows[e.NewEditIndex].FindControl("lblValKeyCode") as Label;
              this.txtKeyCode.Text = lblValKeyCode.Text;
              this.txtKeyDescription.Text = lblValKeyDescription.Text;
              imgbtnFilter_Click(null, null);
          //}
          //else
          //{
              //RowUpdate((int)ViewState["editIndex"]);
              //ViewState.Remove("updateFlag");
              //ViewState.Remove("editFlag");
              //ViewState.Remove("editIndex");
          //}
      }
      protected void dgvSortKey_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
      {
          dgvSortKey.EditIndex = -1;
          imgbtnFilter_Click(null, null);
      }
      protected void dgvSortKey_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
      {
          this.dvDetialContent.Visible = true;
          Label lblValKeyDescription = dgvSortKey.Rows[e.NewSelectedIndex].FindControl("lblValKeyDescription") as Label;
          Label lblValKeyCode = dgvSortKey.Rows[e.NewSelectedIndex].FindControl("lblValKeyCode") as Label;
  
          this.txtKeyCode.Text = lblValKeyCode.Text;
          this.txtKeyDescription.Text = lblValKeyDescription.Text;
      }
      protected void dgvSortKey_PageIndexChanged(object sender, EventArgs e)
      {
  
      }
      protected void dgvSortKey_PageIndexChanging(object sender, GridViewPageEventArgs e)
      {
          dgvSortKey.PageIndex = e.NewPageIndex;
          imgbtnFilter_Click(null, null);
      }
      protected void dgvSortKey_RowUpdated(object sender, GridViewUpdatedEventArgs e)
      {
  
      }
      protected void dgvSortKey_RowDeleting(object sender, GridViewDeleteEventArgs e)
      {
          String jsScript = "";
          jsScript += "var answer=confirm('Delete this Instruction Key?');\n";
          jsScript += "if (!answer){\n";
          jsScript += " document.getElementById('ctl00_cthContent_hdDelete').Value = 'DELETE';\n";
          jsScript += "}\n";
  
          //return;
          ScriptManager.RegisterStartupScript(this, this.GetType(), "script", jsScript, true);
  
          List&lt;SqlDbParameter&gt; list = new List&lt;SqlDbParameter&gt;();
  
          Label lblValKeyCode = dgvSortKey.Rows[e.RowIndex].FindControl("lblValKeyCode") as Label;
          Label lblValKeyDescription = dgvSortKey.Rows[e.RowIndex].FindControl("lblValKeyDescription") as Label;
          list.Add(new SqlDbParameter("@code", lblValKeyCode.Text));
          list.Add(new SqlDbParameter("@name", lblValKeyDescription.Text));
  
          CoreUtility.ExecuteNonQuery("DELETE FROM [InstructionKey] WHERE KeyCode=@code and KeyDescription=@name;", list);
          Initial();
          this.dvDetialContent.Visible = false;
          dgvSortKey.EditIndex = -1;
          imgbtnFilter_Click(null, null);
      }
      protected void dgvSortKey_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          string id = e.CommandName;
      }
      protected void dgvSortKey_RowDeleted(object sender, GridViewDeletedEventArgs e)
      {
  
      }
      protected void gv_drb(object sender, GridViewRowEventArgs e)// 
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              LinkButton lnkbtnresult = (LinkButton)e.Row.FindControl("lnkdelete");
              //raising javascript confirmationbox whenver user clicks on link button
              lnkbtnresult.Attributes.Add("onclick", "javascript:return ConfirmationBox()");
          }
      }
  </code></pre>