How add an event to a new control?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guilherme21922
    New Member
    • Jan 2008
    • 28

    How add an event to a new control?

    I created a new dropdownlist with the event selectedIndexCh anged, but he never dispared!! what i am doing wrong?

    Thanks

    for (int i = 0; i < 2; i++)
    {
    DropDownList dl = new DropDownList();

    dl.ID = dl + i.ToString();
    dl.DataTextFiel d = "name";
    dl.Items.Add("1 ");
    dl.Items.Add("2 ");
    dl.Items.Add("3 ");
    dl.Items.Add("4 ");
    dl.DataBind();
    dl.AutoPostBack = true;
    dl.SelectedInde xChanged += new EventHandler(dl _SelectedIndexC hanged);

    TableRow linha = new TableRow();
    TableRow cabecalho = new TableRow();

    TableCell cell = new TableCell();
    cell.Controls.A dd(dl);
    linha.Cells.Add (cell);
    TableReversao.R ows.Add(linha);
    }
  • guilherme21922
    New Member
    • Jan 2008
    • 28

    #2
    and i have created the function on the c# too..

    protected void dl_SelectedInde xChanged(object sender, EventArgs e)
    {

    }

    no compilation error

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      And now what did you want it to do?
      (I would guess there is trouble with autopostback and dynamic controls)

      Comment

      • guilherme21922
        New Member
        • Jan 2008
        • 28

        #4
        Originally posted by Plater
        And now what did you want it to do?
        (I would guess there is trouble with autopostback and dynamic controls)
        the problem is: when i change the selected item the event is not dispared

        Comment

        Working...