By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

How add an event to a new control?

P: 28
I created a new dropdownlist with the event selectedIndexChanged, 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.DataTextField = "name";
dl.Items.Add("1");
dl.Items.Add("2");
dl.Items.Add("3");
dl.Items.Add("4");
dl.DataBind();
dl.AutoPostBack = true;
dl.SelectedIndexChanged += new EventHandler(dl_SelectedIndexChanged);

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

TableCell cell = new TableCell();
cell.Controls.Add(dl);
linha.Cells.Add(cell);
TableReversao.Rows.Add(linha);
}
Apr 1 '08 #1
Share this Question
Share on Google+
3 Replies


P: 28
and i have created the function on the c# too..

protected void dl_SelectedIndexChanged(object sender, EventArgs e)
{

}

no compilation error
Apr 1 '08 #2

Plater
Expert 5K+
P: 7,872
And now what did you want it to do?
(I would guess there is trouble with autopostback and dynamic controls)
Apr 1 '08 #3

P: 28
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
Apr 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.