Cant fire dropDownList selection从后端更改事件
本文关键字:事件 后端 fire dropDownList selection Cant | 更新日期: 2023-09-27 18:01:02
我无法在Selection更改时激发该方法。我正在从代码后面添加DropDownList本身。代码:
private TableCell CreateMTPLTypeCell(int insurerId, string MTPLType)
{
TableCell rg = new TableCell();
rg.ID = string.Concat("rg_", insurerId);
rg.CssClass = "formItem";
//if (insurerId == 14)
//{
DropDownList ddl = new DropDownList();
ddl.ID = "MTPLTypes";
ddl.Items.Add(new ListItem("Standard", "1")); // add list items
ddl.Items.Add(new ListItem("DubultOCTA", "2"));
ddl.Items.Add(new ListItem("DubultOCTA+vējst", "3"));
//ddl.SelectedIndex =
// ddl.Items.IndexOf(ddl.Items.
// FindByValue(MTPLType));
ddl.SelectedIndexChanged += new EventHandler(MTPLType_selectedIndexChange);
ddl.AutoPostBack = true;
rg.Controls.Add(ddl);
//}
return rg;
}
void MTPLType_selectedIndexChange(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
int insurerId = Int32.Parse(ddl.ID.Replace("rg_", ""));
MTPLQuotes quotes = proposal.Properties.MtplQuotes[insurerId];
if (quotes == null) return;
proposal.GetSingleMTPLQuote(insurerId, Helpers.PortalUtilities.CurrentUser, BrokerInfo.GetBrokerInfo().Country.ID);
DrawMtplQuotes(mtplPaymentMappingsCount > 0);
}
我是否遗漏了DropDownList对象上的一些额外参数?
有时它是这样工作的:在选择Change之后,它开始"加载",但它没有到达方法。:/
在同一类中,我有一个带有onChange事件的表Cell(Text_Change(->这可以正常工作
private TableCell CreateInsurerMtplDiscountCell(int insurerId, decimal discount)
{
TableCell c = new TableCell();
c.CssClass = "formItem";
c.Style[HtmlTextWriterStyle.PaddingLeft] = "25px";
TextBox txt = new TextBox();
txt.ID = string.Format("ins_disc_{0}", insurerId);
txt.Text = discount > 0 ? discount.ToString() : "";
txt.TextChanged += new EventHandler(insurerDiscountPercent_TextChanged);
txt.AutoPostBack = true;
txt.Width = new Unit(40);
c.Controls.Add(txt);
Literal l = new Literal();
l.Text = "%";
c.Controls.Add(l);
return c;
}
void insurerDiscountPercent_TextChanged(object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
int insurerId = Int32.Parse(txt.ID.Replace("ins_disc_", ""));
MTPLQuotes quotes = proposal.Properties.MtplQuotes[insurerId];
if (quotes == null) return;
decimal discountPercent;
if (!Decimal.TryParse(txt.Text, out discountPercent))
discountPercent = 0;
quotes.InsurerDiscountPercent = discountPercent;
foreach (MTPLQuote quote in quotes.Quotes)
ApplyMtplInsurerDiscount(quote, discountPercent);
DrawMtplQuotes(mtplPaymentMappingsCount > 0);
}
修复了它-问题是关于TableCell.ID(rg.ID=string.Concat("rg_",insurerId(;(。去掉它后一切都很好。有人知道为什么会这样吗?
我认为您必须在创建新控件后刷新您的网站。我建议你使用AJAX更新面板(这样你就不必刷新整个网站(。
-
要添加OnChanged事件名称,您还应该能够添加字符串名称,而不是事件处理程序本身。
ddl.SelectedIndexChanged="MTPLType_selectedIndexChange";
-
我认为您必须使用
"protected void"
而不是"private void"
——由于权限限制的控制原因,它是不可访问的。
您应该将SelectedIndexChanged
事件绑定到Page_PreInit
事件的下拉列表。
那么它应该会起作用。