0

我有显示与特定产品无关的关联的 ModalPopupExtenders。与产品相关的关联显示在选项卡容器中,旁边有删除图像按钮。当我早些时候进行测试时,我注意到我从 tabcontainer 中删除的关联不会显示在模式中,除非我单击浏览器中的刷新按钮。有没有我可以使用的代码,这样当我点击删除按钮时,它会自动刷新我的模态,这样我就不会有额外的步骤了?

<!-- Targets -->
<asp:TabPanel ID="tab8" runat="server" HeaderText="Targets">
<HeaderTemplate>Targets</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvTargets" runat="server" DataSourceID="dsTargets" DataKeyNames="TargetID">   
        <ItemTemplate>
            <li><%# Eval("TargetName")%>
            <asp:ImageButton ID="DeleteTargetButton" runat="server" Style="float:right;" AlternateText="" ImageUrl="../../images/delete.png" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this target audience?')" />
            </li>
        </ItemTemplate>
        </asp:ListView>
        </ul>
    </ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>

 <!-- Add a Target -->
      <li>
        <asp:LinkButton ID="TargetButton" runat="server">Target</asp:LinkButton>
        <asp:Panel ID="TargetPanel" runat="server" CssClass="modalPopup" Style="display:none">
            <asp:CheckBoxList ID="cbxAddTarget" runat="server" DataSourceID="dsNewTargets" DataTextField="TargetName" DataValueField="TargetID"></asp:CheckBoxList>
            <asp:Button ID="SubmitTargets" runat="server" Text="Submit" />
            <asp:Button ID="CancelSubmitTargets" runat="server" Text="Cancel" />
        </asp:Panel>
        <asp:ModalPopupExtender ID="TargetModal" runat="server" BackgroundCssClass="modalBackground" CancelControlID="CancelSubmitTargets" DropShadow="True" DynamicServicePath="" Enabled="True" PopupControlID="TargetPanel" TargetControlID="TargetButton"></asp:ModalPopupExtender>
    </li>

    Protected Sub SubmitTargets_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitTargets.Click
    DocumentModal.Hide()
    dsNewTargets.DataBind()
    For Each Target As ListItem In cbxAddTarget.Items
        If Target.Selected Then
            Dim sqlAddTarget As String = Nothing
            'SQL INSERT: TargetLink Table
            sqlAddTarget = "INSERT INTO TargetLink (ProductID, TargetID) VALUES (" & ProductID.Value & ", " & Target.Value & ")"
            sqlAddTarget.Replace("'", "''")
            Dim SqlConnection As New SqlConnection("Server=off-db1;uid=productsDB_admin;pwd=******;database=Products")
            SqlConnection.Open()
            Dim sqlCommand As New SqlCommand(sqlAddTarget, SqlConnection)
            sqlCommand.ExecuteNonQuery()
            SqlConnection.Close()
        End If
    Next
    Response.Redirect(Request.RawUrl)
End Sub   

    Protected Sub dsTargets_Deleted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.Exception Is Nothing Then
        'rebind the new targets list to show updates
        dsNewTargets.DataBind()
    End If
End Sub
4

1 回答 1

1

我想我明白你想要做什么。当您从选项卡容器中删除项目时,请尝试重新绑定提供添加目标列表的数据源控件,如下所示:

//code to delete targets from tab container

dsNewTargets.DataBind();

编辑:添加了通过数据源控制删除重新绑定的方法。

为 dsTargets(您要从中删除的那个)添加一个 OnDeleted 事件处理程序。

Protected Sub dsTargets_Deleted(sender As Object, e As SqlDataSourceStatusEventArgs)
    If e.Exception Is Nothing Then
        'rebind the new targets list to show updates
        dsNewTargets.DataBind()
    End If
End Sub

编辑:数据源控制可能正在缓存结果。添加了禁用缓存的代码。

尝试将以下行添加到您的 Page_Load 事件中:

Response.Cache.SetCacheability(HttpCacheability.NoCache)
于 2011-08-29T21:03:41.077 回答