第一次回发后,GridView不会更改选定的行

时间:2015-09-14 06:13:09

标签: c# asp.net gridview webforms

我有一个用户控件来启用表中的单选,其中包含UpdatePanel内的GridView

<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>

当我点击popup-content并点击btnSelection时再次隐藏时,会通过jquery对话框显示div btnSaveSelection。 在弹出窗口关闭时,我使用选定的行信息更新文本框。

我使用此行数据绑定事件来启用行选择,突出显示所选行

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

我第一次打开弹出窗口时效果非常好。从第二次开始,如果我之前选择了一行并确认,那么当我点击一行时,我看不到新选择的行突出显示。回发被执行并且在服务器端正确选择了行,因为在保存选择时,我看到文本框被更新为正确的值。问题是客户端不会使用突出显示更改来呈现网格视图。

请注意,如果我在没有确认任何内容的情况下打开和关闭弹出窗口,一切正常,我会看到各个行在点击时突出显示。

这似乎是一个与select事件本身无关的客户端渲染问题,因为如果我启用分页,当有一个先前选择的行时,当我点击“下一步”按钮时,我看不到新页面。只有当我从未确认任何事情时,我才能看到其他页面。

令人不安的是,如果我在点击一行时检查发送给客户端的响应内容,我会看到正确的table,即带有背景的tr颜色是我点击的颜色。只是这不会呈现给客户端!

我尝试将事件从RowDataBound更改为RowCreated;我尝试将OnSelectedIndexChanged事件附加到gridview并在代码隐藏中强制upSelectionPopup.Update();,但代码中和运行时期间的所有内容似乎都正确,直到我应该在浏览器中看到新的gridview,我没有。

有什么想法吗?谢谢

0 个答案:

没有答案