title: GridView doesn't change selected row after first postback
body: <p>I have a User Control to enable single selection from a table, which contains a GridView inside an UpdatePanel</p>
  
  <pre><code>&lt;asp:UpdatePanel runat="server" ID="upSelection" UpdateMode="Conditional" ChildrenAsTriggers="false"&gt;
      &lt;ContentTemplate&gt;
  &lt;asp:TextBox runat="server" ID="txtControlText" SkinID="M_Selection" ReadOnly="true"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Button runat="server" ID="btnSelection" Text="..." CssClass="btnSelection" OnClick="btnSelection_Click" CausesValidation="false" /&gt;&lt;asp:Panel runat="server" ID="popupSelection" CssClass="popup"&gt;
          &lt;asp:UpdatePanel runat="server" ID="upSelectionPopup" UpdateMode="Conditional" class="updatePanel"&gt;
              &lt;ContentTemplate&gt;
                  &lt;div class="popup-content"&gt;
                      &lt;asp:GridView ID="gvSelection"  SelectedRowStyle-BackColor="#FFBCBC"  runat="server" OnRowDataBound="gvSelection_RowDataBound"&gt;
                      &lt;/asp:GridView&gt;
                  &lt;/div&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;        
                  &lt;asp:ImageButton runat="server" ID="btnSaveSelection" SkinID="Save" OnClick="btnSaveSelection_Click" CausesValidation="false" /&gt;&lt;/ContentTemplate&gt;&lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>The div <code>popup-content</code> is shown via jquery dialog when I click on <code>btnSelection</code> and hidden again when i click on <code>btnSaveSelection</code>.
  On popup closed, I update the textbox with the selected row information.</p>
  
  <p>I use this row data bound event to enable row selection, which highlights the selected row </p>
  
  <pre><code>protected void gvSelection_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
          e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink((GridView)sender, "Select$" + e.Row.RowIndex);
  }
  </code></pre>
  
  <p>This works perfectly fine the first time I open the popup. From the second time, if I previously selected a row and confirmed, what happens is that when I click on a row I don't see the newly selected row highlighted. the postback gets executed and the row is selected correctly server-side, because on saving the selection, I see the textbox gets updated to the right value. The problem is that the client doesn't render the gridview with the highlight change.</p>
  
  <p>Note that if I open and close the popup without ever confirming anything, everything works correctly, I see the various rows being highlighted on click.</p>
  
  <p>this seems to be a client render problem unrelated to the select event itself, because if I enable paging, when there is a previously selected row, I don't see the new page when I click on the "next" button. I am able to see the other pages only if I never confirm anything.</p>
  
  <p>The unnerving thing is that if I inspect the content of the response that gets sent to the client when I click on a row, inside it I see the correct <code>table</code>, ie the <code>tr</code> with background color is the one I just clicked. It's just that this doesn't get rendered to the client!</p>
  
  <p>I tried changing the event from RowDataBound to RowCreated; I tried attaching the OnSelectedIndexChanged event to the gridview and forcing <code>upSelectionPopup.Update();</code> in the code-behind, but everything in the code and during runtime seems right, right up to the point where I should see the new gridview in the browser, which I don't.</p>
  
  <p>Any ideas? Thank you</p>