2009-12-07 4 views
0

J'ajoute des enregistrements à une base de données à partir d'une fenêtre contextuelle modale. Après avoir masqué la fenêtre contextuelle modale, la page n'a pas été actualisée (même si j'ai lié de nouveau les contrôles). J'ai examiné quelques articles sur le web à ce sujet, mais la solution me échappe toujours. J'ai joint mon code après avoir supprimé certains détails supplémentaires.Comment actualiser DataGrid et DropDown sur la page principale après avoir masqué la fenêtre contextuelle modale

Il semble que je doive provoquer une publication, mais je ne sais pas ce qui doit être changé. Certains messages ont parlé de l'extension étant égaré.

<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server"> 

<div class="divBorder"> 

     <asp:DataGrid id="dgrSessionFolders" runat="server" BorderWidth="2px" 
      BorderStyle="Solid" BorderColor="#C0C0FF" 
      Font-Names="Arial" Font-Bold="True" Font-Size="8pt" GridLines="Horizontal" AutoGenerateColumns="False" 
      PageSize="9999" AllowPaging="False" OnItemCommand="dgrSessionFolders_Command" OnItemDataBound="CheckSessionFolderStatus" 
      HorizontalAlign="Left" ForeColor="Blue" ShowFooter="True" CellPadding="2" 
      OnSortCommand="dgrSessionFolders_Sort" AllowSorting="True"> 
     </asp:DataGrid> 
</div> 
&nbsp;&nbsp;&nbsp; 
<asp:Label ID="Errormsg" runat="server" ForeColor="#CC0000"></asp:Label> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" ChildrenAsTriggers="false" UpdateMode="Conditional">  
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="btnEditTopic" /> 
    <asp:AsyncPostBackTrigger ControlID="btnAdd" /> 
    <asp:AsyncPostBackTrigger ControlID="btnUpdate" /> 
    <asp:AsyncPostBackTrigger ControlID="btnDelete" /> 
    <asp:AsyncPostBackTrigger ControlID="btnClear" /> 
    <asp:AsyncPostBackTrigger ControlID="btnAddTopic" /> 
    <asp:AsyncPostBackTrigger ControlID="btnUpdateTopic" /> 
    <asp:AsyncPostBackTrigger ControlID="btnDeleteTopic" /> 
</Triggers> 
<ContentTemplate> 
    <asp:panel id="pnl" runat="server" HorizontalAlign="Center" Height="48px" Width="100%" > 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <asp:ImageButton ID="btnEditTopic" runat="server" AlternateText="Edit Topic" 
     ImageUrl="~/App_Themes/Common/images/BtnEditTopic.jpg" Height="28px"> 
    </asp:ImageButton> 
    <cc1:ModalPopupExtender ID="btnEditTopic_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground" 
     DropShadow="true" Enabled="true" PopupControlID="pnlEditTopic" TargetControlID="btnEditTopicHidden" 
     CancelControlID="btnEditTopicClose"> 
    </cc1:ModalPopupExtender> 
    <asp:ImageButton ID="btnAdd" runat="server" AlternateText="Add Folder" 
     ImageUrl="~/App_Themes/Common/images/BtnAddFolder.jpg" Height="28px"> 
    </asp:ImageButton> 
    <asp:ImageButton ID="btnUpdate" runat="server" AlternateText="Update Folder" 
     ImageUrl="~/App_Themes/Common/images/BtnUpdateFolder.jpg" Height="28px"> 
    </asp:ImageButton> 
    <asp:ImageButton ID="btnDelete" runat="server" AlternateText="Delete Folder" 
     ImageUrl="~/App_Themes/Common/images/BtnDeleteFolder.jpg" Height="28px"> 
    </asp:ImageButton> 
    <asp:ImageButton ID="BtnClear" runat="server" AlternateText="Clear Screen Input Fields" 
     ImageUrl="~/App_Themes/Common/images/BtnAddMode.jpg" Height="28px"> 
    </asp:ImageButton> 
    <asp:Button ID="btnEditTopicHidden" runat="server" Enabled="false" Text="" Style="visibility: hidden" /> 
</asp:panel> 

<asp:Panel ID="pnlEditTopic" runat="server" CssClass="modalPopupEditTopic" Style="display: none;" > 
    <table cellspacing="0" class="borderTable0" width="100%" style=""> 
     <tr> 
      <td colspan="10" class="Subhdr" align="center" style="width:100%"> 
       <asp:label id="lblTopicScreenHdr" Cssclass="ScreenHdr" runat="server">Topic Maintenance</asp:label> 
      </td> 
     </tr> 
     <tr> 
      <td colspan="6"> 
       <asp:Label ID="TopicPopErrorMsg" runat="server" ForeColor="#CC0000">&nbsp;</asp:Label> 
      </td> 
     </tr> 
     <tr style="height:4px"> 
      <td colspan="6" align="center"> 
       <asp:ImageButton ID="btnAddTopic" runat="server" AlternateText="Add Topic" 
        ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px"> 
       </asp:ImageButton> 
       <asp:ImageButton ID="btnUpdateTopic" runat="server" AlternateText="Update Topic" 
        ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px"> 
       </asp:ImageButton> 
       <asp:ImageButton ID="btnDeleteTopic" runat="server" AlternateText="Delete Topic" 
        ImageUrl="~/App_Themes/Common/images/BtnDelete.jpg" Height="28px"> 
       </asp:ImageButton> 
       <asp:ImageButton ID="btnEditTopicClose" runat="server" AlternateText="Close Edit Topic Popup" 
        ImageUrl="~/App_Themes/Common/images/BtnCancel.jpg" Height="28px"> 
       </asp:ImageButton> 
      </td> 
     </tr> 
    </table> 
</asp:Panel> 

</ContentTemplate> 
</asp:UpdatePanel> 
</asp:Content> 

Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click 

    'Add the Topic table entry 
    AddTopic() 

    'Display an informational message 
    Errormsg.Text = "The Topic has been successfully added, thank you! " 
    Errormsg.ForeColor = Drawing.Color.Blue 

    'Rebind the Topic Drop Down and set to added Topic 
    ddlSessionTopic.DataBind() 
    ddlSessionTopic.SelectedValue = drTopic("TOPC_ID") 

    'Rebind the Session Folders grid 
    RebindGrid() 

    'Hide the Topic Popup 
    btnEditTopic_ModalPopupExtender.Hide() 

End Sub 

Private Sub RebindGrid() 
    cnnSQL = New SqlConnection(strConnection) 
    cmdSQL = New SqlCommand("GetSessionFoldersForGrid", cnnSQL) 
    cmdSQL.CommandType = CommandType.StoredProcedure 
    cmdSQL.Parameters.Clear() 
    cnnSQL.Open() 
    dadSQL = New SqlDataAdapter(cmdSQL) 
    dadSQL.SelectCommand = cmdSQL 
    dadSQL.Fill(dtSessionFolderGrid) 
    cnnSQL.Close() 
    dvSessionFolderGrid = dtSessionFolderGrid.DefaultView 
    dvSessionFolderGrid.Sort = String.Format("{0} {1}{2}", so.Sortfield, so.SortDirection, so.SortSuffix) 
    dgrSessionFolders.DataSource = dvSessionFolderGrid 
    dgrSessionFolders.DataBind() 
End Sub 
+0

James Je pense Datagrid.DataBind() est la seule option –

+0

Oh, désolé ça aiderait! C'est ADO et j'effectue le databind là. Je vais poster dans une minute ... Merci – James

+0

Pouvez-vous poster le code pour RebindGrid, qu'est-ce que vous utilisez pour un DataSource? Pour DropDownList, essayez de réaffecter le DataSource avant d'appeler DataBind(). – Phaedrus

Répondre

0

Vous devez Upate le panneau de mise à jour si vous voulez que votre grille à nouveau binded.

'Ajouter l'entrée de table des sujets AddTopic()

'Display an informational message 
Errormsg.Text = "The Topic has been successfully added, thank you! " 
Errormsg.ForeColor = Drawing.Color.Blue 

'Rebind the Topic Drop Down and set to added Topic 
ddlSessionTopic.DataBind() 
ddlSessionTopic.SelectedValue = drTopic("TOPC_ID") 

'Rebind the Session Folders grid 
RebindGrid() 

'Hide the Topic Popup 
btnEditTopic_ModalPopupExtender.Hide() 

' Ajouter l'entrée de table des sujets AddTopic()

'Display an informational message 
Errormsg.Text = "The Topic has been successfully added, thank you! " 
Errormsg.ForeColor = Drawing.Color.Blue 

'Rebind the Topic Drop Down and set to added Topic 
ddlSessionTopic.DataBind() 
ddlSessionTopic.SelectedValue = drTopic("TOPC_ID") 

'Rebind the Session Folders grid 
RebindGrid() 
UpdatePanel1.Update 

'Hide the Topic Popup 
btnEditTopic_ModalPopupExtender.Hide() 
Questions connexes