【发布时间】:2015-09-14 06:13:08
【问题描述】:
我有一个用户控件来启用表中的单选,该表在 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>
当我点击btnSelection 时,div popup-content 通过 jquery 对话框显示,当我点击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);
}
这在我第一次打开弹出窗口时效果很好。从第二次开始,如果我之前选择了一行并确认,那么当我单击一行时,我看不到新选择的行突出显示。回发被执行,并且在服务器端正确选择了行,因为在保存选择时,我看到文本框更新为正确的值。问题是客户端没有呈现带有高亮变化的gridview。
请注意,如果我在没有确认任何内容的情况下打开和关闭弹出窗口,则一切正常,我会看到点击时突出显示的各个行。
这似乎是与选择事件本身无关的客户端渲染问题,因为如果我启用分页,当有先前选择的行时,当我单击“下一步”按钮时,我看不到新页面。只有当我从不确认任何事情时,我才能看到其他页面。
令人不安的是,如果我在单击一行时检查发送给客户端的响应内容,我会在其中看到正确的table,即带有背景颜色的tr我刚刚点击。只是这并没有呈现给客户端!
我尝试将事件从 RowDataBound 更改为 RowCreated;我尝试将 OnSelectedIndexChanged 事件附加到 gridview 并在代码隐藏中强制 upSelectionPopup.Update(); ,但代码中和运行时期间的所有内容似乎都是正确的,直到我应该在浏览器中看到新的 gridview,我没有不。
有什么想法吗?谢谢
【问题讨论】:
标签: c# asp.net gridview webforms