我弹出一个面板中有两个dropDownLists。当我在第一个dropDownList中更改一个值时,我想用第一个dropDownList中选择的值填充seconde dropDownList。就像我有AutoPostBack = "true"
一样,页面总是令人耳目一新,PopUp也会消失。实际上我只想更新PopUp上的面板。
我正在使用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>
答案 0 :(得分: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>
答案 1 :(得分:0)
我遇到了类似的问题,密钥位于我设置 Items do Dropdown 的部分。当你设置这些 Items 时,它会在页面重新加载后选择第一个(使用autopostback)。
如果这是你的问题,试试这个:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillDropDown();
}
}