0

我在弹出的面板中有两个 dropDownLists。当我更改第一个 dropDownList 中的一个值时,我想用第一个 dropDownList 中选择的值填充第二个 dropDownList。就像我AutoPostBack = "true"的页面总是令人耳目一新,弹出窗口消失了。事实上,我只想更新弹出窗口上的面板。

我正在使用AsyncPostBackTrigger.

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
            PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
    </asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
        Style="display: none">
        <table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
            cellpadding="5" cellspacing="0">
            <tr style="background-color: #D55500">
                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                    align="center">
                    Insert Product
                </td>
            </tr>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <tr>
                        <td align="right" style="width: 45%">
                            Category:
                        </td>
                        <td> 
                            <asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Product:
                        </td>
                        <td>
                            <asp:DropDownList id="DropDownList2" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                </ContentTemplate>
                <Triggers> 
                    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
                </Triggers> 
            </asp:UpdatePanel>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
                    <asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>
4

2 回答 2

0

我遇到了类似的问题,关键在于我设置Items do Dropdown的部分。当您设置这些项目时,它会在页面重新加载后选择第一个项目(使用自动回发)。

如果这是您的问题,请尝试以下操作:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        fillDropDown();
    }
}
于 2013-09-04T11:39:39.933 回答
0

尝试这个:

<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
        Style="display: none">
        <table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
            cellpadding="5" cellspacing="0">
            <tr style="background-color: #D55500">
                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                    align="center">
                    Insert Product
                </td>
            </tr>


                    <tr>
                        <td align="right" style="width: 45%">
                            Category:
                        </td>
                        <td> 
                            <asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Product:
                        </td>
                        <td>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                            <asp:DropDownList id="DropDownList2" runat="server">
                            </asp:DropDownList></ContentTemplate>
                <Triggers> 
                    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
                </Triggers> 
            </asp:UpdatePanel>
                        </td>
                    </tr>

            <tr>
                <td>
                </td>
                <td>
                    <asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
                    <asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>
于 2013-09-04T10:40:14.247 回答