Asp ModalPopupExtender 不显示详细信息视图

发布于 2024-09-12 00:49:28 字数 4724 浏览 0 评论 0原文

当用户在 GridView 中选择“详细信息”按钮时,我在 updatePanel 中使用 ModalPopupExtender 来显示详细信息视图。

问题是,当选择按钮时,不会显示弹出窗口。我已经单步执行了代码,并且 mdlPopup.Show() 方法正在执行,但弹出窗口没有“显示”有人可以帮助我解决正在发生的事情吗? 这是我的代码:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetRequests"
    TypeName="RequestDAL" SortParameterName="SortExpression"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourceDetails" runat="server" SelectMethod="GetRequestsDetail"
    OnSelecting="OdsDetail_Selecting" TypeName="RequestDAL"></asp:ObjectDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RequestID"
    DataSourceID="ObjectDataSource1" EnableModelValidation="True" AllowSorting="True"
    CellPadding="10" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="gv_SelectedIndexChanged">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="DateSubmit" HeaderText="DateSubmit" SortExpression="DateSubmit" />
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="lName" />
        <asp:BoundField DataField="FirstDate" HeaderText="Date" SortExpression="FirstDate" />
        <asp:BoundField DataField="BeginTime" HeaderText="Begin Time" SortExpression="beginTime" />
        <asp:BoundField DataField="EndTime" HeaderText="End Time" SortExpression="endTime" />
        <asp:BoundField DataField="Lab" HeaderText="Lab" SortExpression="room" />
        <asp:BoundField DataField="ClassName" HeaderText="Class" SortExpression="Class" />
        <asp:BoundField DataField="Semester" HeaderText="Semester" SortExpression="term" />
        <asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="id" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="btnDetails" runat="server" Text="Details" CommandName="Select" /></ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>


<asp:Panel ID="pnlPopup" runat="server" Style="display: none" Width="500px">
    <asp:UpdatePanel ID="updatePnlRequestDetail" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
            <Ajax:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
            <asp:Label ID="lblRequestDetail" runat="server" Text="Request Detail" BackColor="LightBlue"
                Width="95%"></asp:Label>
            <asp:DetailsView ID="dvRequestDetail" DataSourceID="ObjectDataSourceDetails" runat="server"
                DefaultMode="Edit" Width="95%" BackColor="White" Visible="false">
                <Fields>
                <asp:BoundField HeaderText="Id"  DataField="RequestID" /></Fields>
            </asp:DetailsView>
            <asp:LinkButton runat="server" ID="btnClose" Text="Close" CausesValidation="false"></asp:LinkButton>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>


protected void gv_SelectedIndexChanged(object sender, EventArgs e)    {

    //show the detail view to render
    dvRequestDetail.Visible = true;    
    // force the databinding
    dvRequestDetail.DataBind();
    // update the detail panel
    updatePnlRequestDetail.Update();
    //show the popup
    mdlPopup.Show();
}
protected void OdsDetail_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    try
    {
        e.InputParameters["id"] = Convert.ToString(this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value);

    }
    catch(Exception ex)
    {
        throw new Exception(ex.Message);
    }           
}

这全部取自我发现的使用 Modal Popup 扩展程序与 ObjectDataSources http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html

I am using a ModalPopupExtender within an updatePanel to show a detailView when a user selects a "Details" Button within a GridView.

The problem is that when the button is selected the popup is not being displayed. I have stepped through the code and the mdlPopup.Show() method is being executed but the popup does not "Show" Could someone perhaps help me out with what is happening?
Here is my Code:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetRequests"
    TypeName="RequestDAL" SortParameterName="SortExpression"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSourceDetails" runat="server" SelectMethod="GetRequestsDetail"
    OnSelecting="OdsDetail_Selecting" TypeName="RequestDAL"></asp:ObjectDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RequestID"
    DataSourceID="ObjectDataSource1" EnableModelValidation="True" AllowSorting="True"
    CellPadding="10" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="gv_SelectedIndexChanged">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="DateSubmit" HeaderText="DateSubmit" SortExpression="DateSubmit" />
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="lName" />
        <asp:BoundField DataField="FirstDate" HeaderText="Date" SortExpression="FirstDate" />
        <asp:BoundField DataField="BeginTime" HeaderText="Begin Time" SortExpression="beginTime" />
        <asp:BoundField DataField="EndTime" HeaderText="End Time" SortExpression="endTime" />
        <asp:BoundField DataField="Lab" HeaderText="Lab" SortExpression="room" />
        <asp:BoundField DataField="ClassName" HeaderText="Class" SortExpression="Class" />
        <asp:BoundField DataField="Semester" HeaderText="Semester" SortExpression="term" />
        <asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="id" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="btnDetails" runat="server" Text="Details" CommandName="Select" /></ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#2461BF" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#EFF3FB" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>


<asp:Panel ID="pnlPopup" runat="server" Style="display: none" Width="500px">
    <asp:UpdatePanel ID="updatePnlRequestDetail" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
            <Ajax:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
            <asp:Label ID="lblRequestDetail" runat="server" Text="Request Detail" BackColor="LightBlue"
                Width="95%"></asp:Label>
            <asp:DetailsView ID="dvRequestDetail" DataSourceID="ObjectDataSourceDetails" runat="server"
                DefaultMode="Edit" Width="95%" BackColor="White" Visible="false">
                <Fields>
                <asp:BoundField HeaderText="Id"  DataField="RequestID" /></Fields>
            </asp:DetailsView>
            <asp:LinkButton runat="server" ID="btnClose" Text="Close" CausesValidation="false"></asp:LinkButton>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>


protected void gv_SelectedIndexChanged(object sender, EventArgs e)    {

    //show the detail view to render
    dvRequestDetail.Visible = true;    
    // force the databinding
    dvRequestDetail.DataBind();
    // update the detail panel
    updatePnlRequestDetail.Update();
    //show the popup
    mdlPopup.Show();
}
protected void OdsDetail_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    try
    {
        e.InputParameters["id"] = Convert.ToString(this.GridView1.DataKeys[this.GridView1.SelectedIndex].Value);

    }
    catch(Exception ex)
    {
        throw new Exception(ex.Message);
    }           
}

This is all taken from a tutorial I found for using Modal Popup extenders with ObjectDataSources http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2024-09-19 00:49:28

我应该做的两件事:

  1. 将 GridView 设置为弹出 UpdatePanel 的 AsyncPostBackTrigger。
  2. 将 TargetControl 和 ModalPopupExtender 放在 PopupControl 面板之外。
<asp:Panel ID="pnlPopup" runat="server" Style="display: none" Width="500px">
    <asp:UpdatePanel ID="updatePnlRequestDetail" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="GridView1" />
        </Triggers>  
        <ContentTemplate>
            <asp:Label ID="lblRequestDetail" runat="server" Text="Request Detail" BackColor="LightBlue" Width="95%"></asp:Label>
            <asp:DetailsView ID="dvRequestDetail" DataSourceID="ObjectDataSourceDetails" runat="server" DefaultMode="Edit" Width="95%" BackColor="White" Visible="false">
                <Fields>
                    <asp:BoundField HeaderText="Id"  DataField="RequestID" />
                </Fields>
            </asp:DetailsView>
            <asp:LinkButton runat="server" ID="btnClose" Text="Close" CausesValidation="false"></asp:LinkButton>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<Ajax:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />

2 thing I whould do:

  1. set your GridView as a AsyncPostBackTrigger for the popup UpdatePanel.
  2. put the TargetControl and the ModalPopupExtender outside of the PopupControl Panel.
<asp:Panel ID="pnlPopup" runat="server" Style="display: none" Width="500px">
    <asp:UpdatePanel ID="updatePnlRequestDetail" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="GridView1" />
        </Triggers>  
        <ContentTemplate>
            <asp:Label ID="lblRequestDetail" runat="server" Text="Request Detail" BackColor="LightBlue" Width="95%"></asp:Label>
            <asp:DetailsView ID="dvRequestDetail" DataSourceID="ObjectDataSourceDetails" runat="server" DefaultMode="Edit" Width="95%" BackColor="White" Visible="false">
                <Fields>
                    <asp:BoundField HeaderText="Id"  DataField="RequestID" />
                </Fields>
            </asp:DetailsView>
            <asp:LinkButton runat="server" ID="btnClose" Text="Close" CausesValidation="false"></asp:LinkButton>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>
<asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
<Ajax:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文