【问题标题】:ModalpopupExtender not hiding, and Gridview not refreshingModalpopupExtender 不隐藏,Gridview 不刷新
【发布时间】:2010-10-08 15:54:13
【问题描述】:

我在 UpdatePanel 中有一个 Gridview,它显示了我的数据库中的一些数据。当你点击一个编辑按钮时,它会在 ModalPopupextender 中打开一个 detailsView。当您在此 detailView 的文本框中输入数据并单击“更新”时,数据库会更新,但弹出窗口不会隐藏。然后,当我通过单击“关闭”手动关闭它时,除非我刷新页面,否则 gridView 不会刷新。我之前能够让它工作,但是在花了一周的时间盯着这个问题之后,我决定请你们看看我做错了什么。

这里有一些代码! (注意:很多都是根据我找到的教程改编的)

<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="gvReservations" runat="server" CssClass="datagrid" DataKeyNames="dateSubmit"
                AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PageSize="10"
                DataSourceID="mainTable" Width="95%" OnRowUpdated="gvReservation_RowUpdated"  OnRowDataBound="OnRowDataBound" OnSelectedIndexChanged="GvReservations_SelectedIndexChanged">
                <Columns>
                    <asp:BoundField DataField="dateSubmit" HeaderText="Date Submitted" SortExpression="dateSubmit"
                        ReadOnly="true" />
                    <asp:BoundField DataField="lName" HeaderText="Name" SortExpression="lName" ReadOnly="true" />
                    <asp:BoundField DataField="startTime" HeaderText="Start Time" SortExpression="startTime"
                        ReadOnly="true" />
                    <asp:BoundField DataField="endTime" HeaderText="End Time" SortExpression="endTime"
                        ReadOnly="true" />
                    <asp:BoundField DataField="labName" HeaderText="Lab" SortExpression="labName" ReadOnly="true" />
                    <asp:BoundField DataField="class" HeaderText="Class" SortExpression="class" ReadOnly="true" />
                    <asp:BoundField DataField="term" HeaderText="Semester" SortExpression="term" ReadOnly="true" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="btnViewDetails" runat="server" Text="more" CommandName="Select" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" Style="display: none;">
        <asp:UpdatePanel ID="updPnlReservationDetail" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
                <ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                    PopupControlID="pnlPopup" CancelControlID="btnClose"  BackgroundCssClass="modalBackground" />
                <asp:DetailsView ID="dvReservationDetail" runat="server" DataSourceID="SqlDetail"
                   OnDataBound="ReservationDetail_DataBound"  CssClass="detailgrid" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
                      Visible="false" Width="100%" OnItemUpdating="ReservationDetail_Updating"   OnItemUpdated="ReservationDetail_Updated">
                    <Fields>

                    <asp:TemplateField HeaderText="ID">
                            <EditItemTemplate>
                                <asp:TextBox ID="tbID" runat="server" Text='<%# Bind("id") %>' ReadOnly="true" />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>

                        <asp:BoundField HeaderText="LabName" DataField="labName" />
                        <asp:BoundField  HeaderText="DateSubmitted" DataField="dateSubmit" />

                         <asp:TemplateField HeaderText="Start Time">
                            <EditItemTemplate>
                               <asp:TextBox ID="startTime" runat="server" Text='<%# Bind("startTime") %>' />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>


                        <asp:TemplateField HeaderText="End Time">
                            <EditItemTemplate>
                                <asp:TextBox ID="endTime" runat="server" Text='<%# Bind("endTime") %>' />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="true" />

                    </Fields>
                </asp:DetailsView>

                <div class="footer">

                    <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Panel>

这些是我认为它会关闭弹出窗口并更新 gridView 的事件

protected void ReservationDetail_Updated(object sender, DetailsViewUpdatedEventArgs e)
    {
        if (this.Page.IsValid)
        {

            //  move the data back to the data object
           // this.dvReservationDetail.UpdateItem(false);
            dvReservationDetail.Visible = false;

            //  hide the modal popup
            mdlPopup.Hide();

            //  refresh the grid

            this.gvReservations.DataBind();
            this.updatePanel.Update();
        }

    }

感谢您的帮助!

【问题讨论】:

    标签: c# asp.net gridview modalpopupextender detailsview


    【解决方案1】:

    尝试在页面上使用单个更新面板 将所有控件放入其中。

    <asp:Panel ID="pnlPopup" runat="server" CssClass="detail" Width="500px" Style="display: none;">
                <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
                <ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                    PopupControlID="pnlPopup" CancelControlID="btnClose"  BackgroundCssClass="modalBackground" />
                <asp:DetailsView ID="dvReservationDetail" runat="server" DataSourceID="SqlDetail"
                   OnDataBound="ReservationDetail_DataBound"  CssClass="detailgrid" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
                      Visible="false" Width="100%" OnItemUpdating="ReservationDetail_Updating"   OnItemUpdated="ReservationDetail_Updated">
                    <Fields>
    
                    <asp:TemplateField HeaderText="ID">
                            <EditItemTemplate>
                                <asp:TextBox ID="tbID" runat="server" Text='<%# Bind("id") %>' ReadOnly="true" />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>
    
                        <asp:BoundField HeaderText="LabName" DataField="labName" />
                        <asp:BoundField  HeaderText="DateSubmitted" DataField="dateSubmit" />
    
                         <asp:TemplateField HeaderText="Start Time">
                            <EditItemTemplate>
                               <asp:TextBox ID="startTime" runat="server" Text='<%# Bind("startTime") %>' />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>
    
    
                        <asp:TemplateField HeaderText="End Time">
                            <EditItemTemplate>
                                <asp:TextBox ID="endTime" runat="server" Text='<%# Bind("endTime") %>' />                                    
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="true" />
    
                    </Fields>
                </asp:DetailsView>
    
                <div class="footer">
    
                    <asp:LinkButton ID="btnClose" runat="server" Text="Close" CausesValidation="false" />
                </div>            
    </asp:Panel>
    

    【讨论】:

    • 这样做使得详细信息视图没有显示在 modalpopup 中
    猜你喜欢
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    相关资源
    最近更新 更多