Piddu
Piddu

Reputation: 383

GridView doesn't change selected row after first postback

I have a User Control to enable single selection from a table, which contains a GridView inside an UpdatePanel

<asp:UpdatePanel runat="server" ID="upSelection" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
<asp:TextBox runat="server" ID="txtControlText" SkinID="M_Selection" ReadOnly="true"></asp:TextBox>
    <asp:Button runat="server" ID="btnSelection" Text="..." CssClass="btnSelection" OnClick="btnSelection_Click" CausesValidation="false" /><asp:Panel runat="server" ID="popupSelection" CssClass="popup">
        <asp:UpdatePanel runat="server" ID="upSelectionPopup" UpdateMode="Conditional" class="updatePanel">
            <ContentTemplate>
                <div class="popup-content">
                    <asp:GridView ID="gvSelection"  SelectedRowStyle-BackColor="#FFBCBC"  runat="server" OnRowDataBound="gvSelection_RowDataBound">
                    </asp:GridView>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>        
                <asp:ImageButton runat="server" ID="btnSaveSelection" SkinID="Save" OnClick="btnSaveSelection_Click" CausesValidation="false" /></ContentTemplate></asp:UpdatePanel>

The div popup-content is shown via jquery dialog when I click on btnSelection and hidden again when i click on btnSaveSelection. On popup closed, I update the textbox with the selected row information.

I use this row data bound event to enable row selection, which highlights the selected row

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);
}

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.

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.

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.

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 table, ie the tr with background color is the one I just clicked. It's just that this doesn't get rendered to the client!

I tried changing the event from RowDataBound to RowCreated; I tried attaching the OnSelectedIndexChanged event to the gridview and forcing upSelectionPopup.Update(); 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.

Any ideas? Thank you

Upvotes: 1

Views: 1262

Answers (1)

ha chitti
ha chitti

Reputation: 139

I think this is due to the update panel. After the content panel try to add

</ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="whicheverbuttonyouaredoing" />
            </Triggers>
        </asp:UpdatePanel>

Upvotes: 1

Related Questions