2010-10-08 92 views
2

我有一個UpdatePanel內的GridView,顯示我的數據庫中的一些數據。當你點擊一個編輯按鈕時,它會在ModalPopupextender中打開一個detailsView。當您在此詳細信息視圖的文本框中輸入數據並單擊「更新」時,數據庫會更新,但彈出窗口不會隱藏。然後,當我通過點擊「關閉」手動關閉它時,除非刷新頁面,否則gridView不刷新。之前我能夠做到這一點,但是花了一個星期的時間注意到這個問題後,我決定讓你們看看我做錯了什麼。ModalpopupExtender不隱藏,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(); 
     } 

    } 

感謝您的幫助事件!

回答

2

嘗試使用第 頁上的單個更新面板將所有控件放置在其中。

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

+0

這樣做使得細節視圖不會顯示在modalpopup內部 – Isawpalmetto 2010-10-08 16:17:04