0

我无法在选择更改上触发该方法。我正在从后面的代码中添加 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);) 上。删除后一切正常。有谁知道为什么会这样?

4

2 回答 2

0

我认为您必须在创建新控件后刷新您的网站。我建议您使用 AJAX-updatepanels(因此您不必刷新整个站点)。

  1. 要添加 OnChanged-Event 名称,您还应该能够添加字符串名称而不是事件处理程序本身。

    ddl.SelectedIndexChanged = "MTPLType_selectedIndexChange";

  2. 我认为对于权限限制的控制原因,您必须使用"protected void"而不是无法访问。"private void"

于 2013-02-25T10:42:37.350 回答
0

您应该将您的SelectedIndexChanged事件绑定到事件的下拉列表中Page_PreInit

然后它应该工作。

于 2013-02-25T10:54:19.243 回答