title: The GridView fired event RowEditing which wasn't handled when search for specific row
body: <p>I have a grid view with 2 columns one for textbox and the other for edit icon. If I click on edit icon, it opened the textbox for editing and the second column will contain update icon and cancel icon. Also there is a search textbox above the gridview to allow the user search for specefic row.</p>
  
  <p><strong>First scenario:</strong> when i have for example 5 rows and click on edit icon in any row, it will open the edit box and i can edit.</p>
  
  <p><strong>Second scenario:</strong> when i type text in search field and click on search button it will retrieve the corresponding row and display it in the grid view alone. </p>
  
  <p><strong>The problem is</strong>  When I click on edit icon for this row (search result), it shows: The GridView fired event RowEditing which wasn't handled</p>
  
  <p><strong>This is my gridview:</strong></p>
  
  <pre><code>&lt;asp:GridView ID="PSGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="StatusID" DataSourceID="PSSqlDataSource" ShowFooter="True" BorderStyle="None" BorderWidth="1px" Width="100%" ShowHeaderWhenEmpty="True" EmptyDataText="No protocal status."
    AllowPaging="true" PageSize="10" CssClass="table table-bordered table-striped table-condensed mb-none" AllowSorting="True" OnRowCommand="PSGridView_RowCommand"&gt;
    &lt;Columns&gt;
      &lt;%--RP col--%&gt;
        &lt;asp:TemplateField HeaderText="Protocol Status" HeaderStyle-CssClass="caption font-green" HeaderStyle-Width="90%"&gt;
          &lt;EditItemTemplate&gt;
            &lt;asp:TextBox ID="PSBind" runat="server" Text='&lt;%# Bind("Des") %&gt;' Width="100%" CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
          &lt;/EditItemTemplate&gt;
          &lt;ItemTemplate&gt;
            &lt;asp:Label ID="PSLabel" runat="server" Text='&lt;%# Bind("Des") %&gt;' Width="100%"&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
          &lt;FooterTemplate&gt;
            &lt;asp:TextBox ID="PS" runat="server" Width="100%" CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
          &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;%--Action col--%&gt;
  
          &lt;asp:TemplateField HeaderText="Actions" HeaderStyle-CssClass="caption font-green" HeaderStyle-Width="10%"&gt;
            &lt;ItemTemplate&gt;
              &lt;asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" ToolTip="Edit"&gt;
                &lt;i class="fa fa-lg fa-pencil"&gt;&lt;/i&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;%--&lt;asp:LinkButton ID="btnDelete" runat="server"  CausesValidation="false"  CommandArgument="&lt;%# Container.DataItemIndex %&gt;" CommandName="DeletePS" OnClientClick="return FinalDeleteConfirm(this, event);" Text="Delete" ToolTip="Delete"&gt;--%&gt;
                &lt;asp:LinkButton ID="btnDelete" runat="server" CausesValidation="false" CommandArgument="&lt;%# Container.DataItemIndex %&gt;" CommandName="DeletePS" OnClientClick="DeleteConfirm()" Text="Delete" ToolTip="Delete"&gt;
                  &lt;i class="fa fa-lg fa-trash-o" style="color:red;"&gt;&lt;/i&gt;&lt;/asp:LinkButton&gt;
            &lt;/ItemTemplate&gt;
  
            &lt;EditItemTemplate&gt;
              &lt;asp:LinkButton ID="btnUpdate" runat="server" CommandName="UpdatePS" CommandArgument="&lt;%# Container.DataItemIndex %&gt;" Text="Update" ToolTip="Confirm"&gt;
                &lt;i class="fa fa-lg fa-check" style="color:green"&gt;&lt;/i&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" ToolTip="Cancel"&gt;
                &lt;i class="fa fa-lg fa-times" style="color:red"&gt;&lt;/i&gt;&lt;/asp:LinkButton&gt;
            &lt;/EditItemTemplate&gt;
  
            &lt;FooterTemplate&gt;
              &lt;button id="btnAdd" class="btn btn-primary btn-circle" type="button" runat="server" onserverclick="btnAdd_Click"&gt;
              &lt;i class="fa fa-plus"&gt;&lt;/i&gt;
              &amp;nbsp;Add Protocol Status   
              &lt;/button&gt;
            &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
  
    &lt;PagerStyle CssClass="pagination-marwa" /&gt;
    &lt;SortedAscendingCellStyle BackColor="#FFFDE7" /&gt;
    &lt;SortedAscendingHeaderStyle BackColor="#FFF9C4" /&gt;
    &lt;SortedDescendingCellStyle BackColor="#FFFDE7" /&gt;
    &lt;SortedDescendingHeaderStyle BackColor="#FFF9C4" /&gt;
  &lt;/asp:GridView&gt;
  
  &lt;asp:SqlDataSource ID="PSSqlDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ProtocolConnectionString %&gt;" SelectCommand="ProtocolStatus_Select" DeleteCommand="ProtocolStatus_Delete" InsertCommand="ProtocolStatus_Insert" UpdateCommand="ProtocolStatus_Update"
    DeleteCommandType="StoredProcedure" InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure" UpdateCommandType="StoredProcedure"&gt;
  
    &lt;DeleteParameters&gt;
      &lt;asp:Parameter Name="StatusID" Type="Int32" /&gt;
    &lt;/DeleteParameters&gt;
  
    &lt;InsertParameters&gt;
      &lt;asp:Parameter Name="Des" Type="String" /&gt;
    &lt;/InsertParameters&gt;
  
    &lt;UpdateParameters&gt;
      &lt;asp:Parameter Name="StatusID" Type="Int32" /&gt;
      &lt;asp:Parameter Name="Des" Type="String" /&gt;
    &lt;/UpdateParameters&gt;
  
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p><strong>code behind c#:</strong></p>
  
  <pre><code>protected void PSGridView_RowCommand(object sender, GridViewCommandEventArgs e) {
          var exist = 0;            
          if (e.CommandName == "DeletePS" )
          {
              some code
          }
  
          else if (e.CommandName == "UpdatePS")
          {
              var exist1 = 0;    
              //When update, check if the new name is already exist in the database
              //*******************************************************************
              var index = Convert.ToInt32(e.CommandArgument);
  
              if (index &gt;= 10)
              {
                  index = index % 10;
              }
  
              var pageSize = PSGridView.PageSize;
              GridViewRow row = PSGridView.Rows[index % pageSize];
              TextBox txt = row.FindControl("PSBind") as TextBox;
              string t = txt.Text;
              exist1 = check_exist(t);
  
              if (exist1 == 1)
              {
                errorboxactions.Attributes.Add("style", "display:block");
                errormsgactions.InnerHtml = "This name already exist ! type another name";
              }
              //if not exist
              //*************
              else
              {
                 PSGridView.UpdateRow(index, true);
                 PSGridView.DataBind();
  
                 updateboxactions.Attributes.Add("style", "display:block");
                 updatemsgactions.InnerHtml = "Protocol Status has been updated successfully";
              }                
          } 
      }
  </code></pre>