我无法在选择更改上触发该方法。我正在从后面的代码中添加 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 对象上的一些额外参数吗?
Atm 的工作原理是这样的:在 selectionChange 之后它开始“加载”但它没有到达该方法。:/
在同一个班级中,我有另一个带有 onChange 事件(Text_Change)的 tableCell -> 这可以正常工作。
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);) 上。删除后一切正常。有谁知道为什么会这样?