【问题标题】:DataBind GridView in modal dialog on button click按钮单击时模式对话框中的 DataBind GridView
【发布时间】:2017-04-24 11:22:04
【问题描述】:

我在模式对话框中绑定数据时遇到问题。 我有一个类似的 ascx 文件

<asp:Panel ID="ModalDialog" runat="server" Style="display: none;">
<asp:UpdatePanel runat="server" ID="UpdatePanel" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <ContentTemplate>
 <asp:GridView runat="server" ID="ResultGridTest" AutoGenerateColumns="true" ShowHeader="true" Width="100%" />
    </ContentTemplate>
    <Triggers>
    <asp:PostBackTrigger ControlID="ResultGridTest" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>

模态对话框作为 jquery 对话框打开

$j("#ModalDialog").dialog("open");

问题是,当我尝试在处理方法中将数据绑定到 ResultGridTest 时,该方法会触发来自另一个控件的传递值,ResultGridHas 没有任何可见数据。 我的处理方法:

protected void GridViewControl_DataBindGridView(object sender, PassSelectedValuesEventArgs<Model> e)
{
    ResultGridTest.DataSource = e.SelectedItems;
    ResultGridTest.DataBind();
}

您知道如何在我的模式对话框中发生事件后绑定数据吗? 请帮忙

【问题讨论】:

    标签: asp.net gridview webforms


    【解决方案1】:

    您的 UpdatePanel 有一个 UpdateMode 作为条件。您需要手动更新它。添加更新面板。更新();在 DataBind() 之后添加到您的方法中。

    【讨论】:

    • 仍然不起作用,ChildrenAsTriggers 应该会产生与 UpdatePanel 上手动触发的 Update 方法相同的效果
    • ChildrenAsTriggers 适用于直接子元素。根据您的说法,UpdatePanel 的直接子元素是哪个?我对是否考虑 ContentTemplate 感到困惑?
    • ResultGridTest 是一个子控件,在 triggerpostback 中定义。如果我错了,不要怪我,我是 ASP 网络表单中的菜鸟
    • 您能否尝试使用 UpdateMode = "Always" 的触发器?还是在不使用触发器的情况下手动更新 UpdatePanel?
    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多