隐藏模式弹出窗口后如何刷新主页上的 DataGrid 和 DropDown

发布于 2024-08-14 14:49:20 字数 6418 浏览 3 评论 0原文

我正在从模式弹出窗口向数据库添加记录。隐藏模式弹出窗口后,页面尚未刷新(即使我已重新绑定控件)。我已经在网上查看了一些关于此问题的帖子,但解决方案仍然无法解决。删除一些额外的细节后,我附上了我的代码。

看来我需要引起回发,但我不知道需要更改什么。有些帖子谈到了扩展器放错了地方。

<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

I am adding records to a database from a modal popup. After hiding the modal popup, the page has not been refreshed (even though I have Re-bound the controls). I have reviewed a few postings on the web about this but the solution still evades me. I have attached my code after removing some of the extra detail.

It seems I need to cause a postback, but I don't know what needs to be changed. Some posts have talked about the extender being misplaced.

<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>
   
<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%" >
            
    <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"> </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

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

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

发布评论

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

评论(2

嘴硬脾气大 2024-08-21 14:49:20

如果您使用 javascript 进行回发怎么办?

表单.提交();

或者你可以谷歌并使用这样的东西: http:// weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

What if you did the postback using javascript?

Form.Submit();

Or you could google and use something like this: http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

剧终人散尽 2024-08-21 14:49:20

如果您希望重新绑定网格,您需要更新更新面板。

'添加主题表条目
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()

'添加主题表条目
添加主题()

'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()

You need to upate the update panel if you want your grid to be re-binded.

'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()

'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()
 UpdatePanel1.Update

'Hide the Topic Popup
btnEditTopic_ModalPopupExtender.Hide()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文