title: ASP.Net GridView - Update Row Command does not revert back to display-only
body: <p>I have a GridView that is populated from a LinqDataSource. When I update a row, the RowCommand fires and the change is persisted to the database, but the Grid does not refresh. I have it in an UpdatePanel and explicitely call Update() in the RowCommand handler, but there is no postback and the page just sits there in Edit mode. Once I click cancel, it will return to view-only and the grid shows the new value.</p>
  
  <p>My suspicion is that something in the wiring of the GridView regarding the data source is wrong. No exception bubbles up, though. A stripped-down copy of the markup is below. Any ideas?</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="uPanel" runat="server" UpdateMode="Conditional" 
    EnableViewState="true" ChildrenAsTriggers="true"&gt;
    &lt;ContentTemplate&gt;
      &lt;asp:LinqDataSource ID="YieldDataSource" runat="server" 
          ContextTypeName="myhDataContext" TableName="vw_drug_yields" 
          OnSelecting="YieldDataSource_Selecting" EnableUpdate="true" /&gt;
      &lt;asp:GridView ID="YieldGridView" runat="server" Width="900px" 
           OnRowDataBound="editGrid_RowDataBound"
           DataSourceID="YieldDataSource" EnableViewState="true"
           OnRowCommand="YieldGridView_RowCommand"&gt;
      &lt;Columns&gt;
        &lt;asp:TemplateField HeaderText="Net Fill" ItemStyle-HorizontalAlign="Center"&gt;
            &lt;ItemTemplate&gt;&lt;%# DataBinder.Eval(Container.DataItem, "net_fill") %&gt;
            &lt;/ItemTemplate&gt;
            &lt;EditItemTemplate&gt;&lt;asp:TextBox ID="tbNetFill" runat="server" 
            Text='&lt;%# DataBinder.Eval(Container.DataItem, "net_fill") %&gt;' &gt;
            &lt;/asp:TextBox&gt;&lt;/EditItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField ShowHeader="False" ItemStyle-Width="40px"&gt;
            &lt;ItemTemplate&gt;
               &lt;asp:ImageButton CommandName="Edit" ID="btnEdit" SkinID="btnEdit" 
               runat="server" ToolTip="Edit" CausesValidation="false"/&gt; 
            &lt;/ItemTemplate&gt;
            &lt;EditItemTemplate&gt;
               &lt;asp:ImageButton CommandName="Update" ID="btnSubmit" SkinID="btnSubmit" 
               runat="server" ToolTip="Save" CausesValidation="true" 
               CommandArgument="&lt;%# ((GridViewRow) Container).DataItemIndex %&gt;" /&gt; 
               &lt;asp:ImageButton CommandName="Cancel" ID="btnCancel" SkinID="btnCancel" 
               runat="server" ToolTip="Cancel" CausesValidation="false"/&gt; 
            &lt;/EditItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
     &lt;/asp:GridView&gt;&lt;/ContentTemplate&gt;&lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>The handler:</p>
  
  <pre><code>protected void YieldGridView_RowCommand(Object sender, 
        GridViewCommandEventArgs e) {
    if (e.CommandName == "Update") {
        try {
            int index = Convert.ToInt32(e.CommandArgument);
  
            GridViewRow gdrow = YieldGridView.Rows[index];
  
            // do some validation and handle update
  
               db.SubmitChanges();
  
            YieldGridView.DataBind();
            uPanel.Update();
        }
        catch (Exception ex) {
            ShowError(this, "Error while updating yields", ex, true);
        }
    }
  </code></pre>