DropDownList/ListItem Problem
-
I am working on this project, when I add items to a drop down list using a list item it wont into the event handler on selectedindexchanged. However, use the other definition for the dropdown to add in items via a string, it actually goes into the event handler on selected index changed, for example when I do this:
ListItem item = new ListItem("One","1"); DropDownList1 = new DropDownList(); DropDownList1.Items.Add(item);
it will add it in, but when I select something different it wont go into the event handler, but when I do this:DropDownList1 = new DropDownList(); DropDownList1.Items.Add("One");
it will go into the event handler. I dont understand why this is. -
I am working on this project, when I add items to a drop down list using a list item it wont into the event handler on selectedindexchanged. However, use the other definition for the dropdown to add in items via a string, it actually goes into the event handler on selected index changed, for example when I do this:
ListItem item = new ListItem("One","1"); DropDownList1 = new DropDownList(); DropDownList1.Items.Add(item);
it will add it in, but when I select something different it wont go into the event handler, but when I do this:DropDownList1 = new DropDownList(); DropDownList1.Items.Add("One");
it will go into the event handler. I dont understand why this is.Make sure "AutoPostBack" is set to "true" and the "SelectedIndexChange" event is actually pointing to your event handler before testing your application. Sometimes when you move or modify your control, it resets everything back to its default settings. Also, unless you are creating a DropDownList dynamically, don't initialize it. This action will also reset it back to its original default settings.
-
Make sure "AutoPostBack" is set to "true" and the "SelectedIndexChange" event is actually pointing to your event handler before testing your application. Sometimes when you move or modify your control, it resets everything back to its default settings. Also, unless you are creating a DropDownList dynamically, don't initialize it. This action will also reset it back to its original default settings.
Hi George, thanks for replying to me. I did all of that already, they are dynamic, I don't understand why it wont work. Have you tried it both ways, I dont know if it's teh IDE or what. Im using .NET 2003 though.
-
I am working on this project, when I add items to a drop down list using a list item it wont into the event handler on selectedindexchanged. However, use the other definition for the dropdown to add in items via a string, it actually goes into the event handler on selected index changed, for example when I do this:
ListItem item = new ListItem("One","1"); DropDownList1 = new DropDownList(); DropDownList1.Items.Add(item);
it will add it in, but when I select something different it wont go into the event handler, but when I do this:DropDownList1 = new DropDownList(); DropDownList1.Items.Add("One");
it will go into the event handler. I dont understand why this is.Anyways, I was able to work around it, I had to basically re-engineer everything I did, and use the second definition using strings instead of ListItems in the DropDownList. Thanks for everything. Sincerely, The Major Rager