title: How to stop GridView edit button from changing after editing is done?
body: <h2>Edit</h2>
  
  <p>I've arrived at a solution which makes any answer on this question irrelevant to my current application of the GridView, however, if you can provide a helpful answer, please do so as others may have the same problem and might come here looking for a solution.</p>
  
  <p>My solution was to use CommandFields in my GridView and then reacting to particular events:</p>
  
  <pre><code>&lt;asp:CommandField ShowSelectButton="true" SelectText="View/Edit" /&gt;
  &lt;asp:CommandField ShowDeleteButton="true" DeleteText="true" /&gt;
  </code></pre>
  
  <p>In my backend code:</p>
  
  <pre><code>protected void gvThings_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {
      // Load data based on the selected row's data key
      // and present an edit form prepopulated with the data.
  }
  
  protected void gvThings_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
      // Select and delete data based on the selected row's data key.
  }
  </code></pre>
  
  <h2>Original Question</h2>
  
  <p>I'm using <code>RowEditing</code> on my GridView to edit the data.</p>
  
  <p>When you click on a row's Edit button, the page changes to show you a form where you can edit and save the changes after which the page reverts back to reload the list and display the data to the user.</p>
  
  <p>The problem is that when the view changes back to the list, there's Update / Cancel links on the record like the GridView thinks its still editing.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>protected void gvSuppliers_RowEditing(object sender, GridViewEditEventArgs e)
  {
      using (Entities db = new Entities())
      {
          // Make a note of the identifier for the row
          // where it can be accessed later
          ViewState.Add("SupplierId", (Guid)gvSuppliers.DataKeys[e.NewEditIndex].Value);
          var supplierId = (Guid)ViewState["SupplierId"];
  
          // Get the data and load the entity
          var supplier = db.Suppliers.FirstOrDefault(x =&gt; x.SupplierId == supplierId);
  
          txtEditName.Text = supplier.Name;
  
          mvSuppliers.ActiveViewIndex = mvSuppliers.Views.IndexOf(vEdit); // go to edit form
      }
  }
  
  protected void btnEdit_Click(object sender, EventArgs e)
  {
      if (!String.IsNullOrEmpty(txtEditName.Text))
      {
          using (Entities db = new Entities())
          {
              // Get the identifier again and update the entity
              var supplierId = (Guid)ViewState["SupplierId"];
              var supplier = db.Suppliers.FirstOrDefault(x =&gt; x.SupplierId == supplierId);
  
              if (supplier != null)
              {
                  supplier.Name = txtEditName.Text;
                  db.SaveChanges();
  
                  // Reload the GridView's data and show it on the page again
                  LoadSuppliers();
                  mvSuppliers.ActiveViewIndex = mvSuppliers.Views.IndexOf(vList); // go back to the list
              }
          }
      }
  }
  </code></pre>