我想寫一個報價生成器。對於每種產品,都有一組選項。我想爲每個選項動態添加一個下拉列表,然後讓它們的SelectedIndexChanged事件全部連線以更新報價成本。如何以編程方式將觸發器添加到ASP.NET UpdatePanel?
我沒有任何麻煩添加DropDownList控件到我的UpdatePanel,但我似乎無法連接事件。
頁面加載後,下拉列表中存在數據,但更改它們不會調用SelectedIndexChanged事件處理程序,QuoteUpdatePanel也不會更新。 我有這樣的事情:
編輯:由於programmatically adding AsyncPostBackTrigger controls is not supported,我有我的代碼更改,但我仍然沒有得到事件:
編輯2:嘗試添加一個佔位符到名單(而不是直接添加下拉到ContentTemplateContainer,仍然沒有事件觸發。
QuotePanel.ASCX
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="QuoteUpdatePanel" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
Cost: <asp:Label ID="QuoteCostLabel" runat="server" />
<fieldset id="standard-options">
<legend>Standard Options</legend>
<asp:UpdatePanel ID="StandardOptionsUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:PlaceHolder ID="StandardOptionsPlaceHolder" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
代碼添加下拉列表和事件它們要絲開:
protected void PopluateUpdatePanel(IEnumerable<IQuoteProperty> standardOptions)
{
foreach (IQuoteProperty standardOp in standardOptions)
{
QuotePropertyDropDownList<IQuoteProperty> dropDownList = new QuotePropertyDropDownList<IQuoteProperty>(standardOp);
dropDownList.SelectedIndexChanged += QuotePropertyDropDown_SelectedIndexChanged;
dropDownList.ID = standardOp.GetType().Name + "DropDownList";
dropDownList.CssClass = "quote-property-dropdownlist";
Label propertyLabel = new Label() {Text = standardOp.Title, CssClass = "quote-property-label"};
StandardOptionsPlaceHolder.Controls.Add(propertyLabel);
StandardOptionsPlaceHolder.Controls.Add(dropDownList);
_standardOptionsDropDownLists.Add(dropDownList);
ScriptManager.RegisterAsyncPostBackControl(dropDownList);
}
}
void QuotePropertyDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
QuoteCostLabel.Text = QuoteCost.ToString();
StandardOptionsUpdatePanel.Update();
}
當然!沒有輸入? – scottm 2010-04-26 23:04:02