Nasser Hamdan
asked on
ASP.NET Drop down list - first item selection problem
Hi,
This is a strange thing ! i have drop down list and when selected i want it to enter the event SelectedIndexChanged,, the problem is that when second item selected it enters no problem ... but if first item is selected then it wont enter that event!! but i need to enter the event whatever item is selected?
Anybody faced this before?
Thanks
This is a strange thing ! i have drop down list and when selected i want it to enter the event SelectedIndexChanged,, the problem is that when second item selected it enters no problem ... but if first item is selected then it wont enter that event!! but i need to enter the event whatever item is selected?
Anybody faced this before?
Thanks
ASKER
Hi Tim,
The problem is that when user first enter my page the first item which is displaying empty text
ListItem li = new ListItem("","0", true);
ddl.Items.Insert(0, li);
is displayed.. and the content of page as default no selection is also displayed.,, now user will selected different option and different content will be displayed also ,,, then user may re-select the first empty option then i need to display the default content that was in first when enter the page.. But the problem is that DDL always dont fire the selectedIndexChange event when first choice is selected !
any ideas?
The problem is that when user first enter my page the first item which is displaying empty text
ListItem li = new ListItem("","0", true);
ddl.Items.Insert(0, li);
is displayed.. and the content of page as default no selection is also displayed.,, now user will selected different option and different content will be displayed also ,,, then user may re-select the first empty option then i need to display the default content that was in first when enter the page.. But the problem is that DDL always dont fire the selectedIndexChange event when first choice is selected !
any ideas?
hammdan_1980,
I assume that you have the .AutoPostBack set to true on the dropdownlist in order to be firing this event. There is no logical reason for it not to fire when any change is made, providing that the dropdownlist is populated correctly and the selectedindexchanged event should be fired when the page is posted back.
TimCottee
I assume that you have the .AutoPostBack set to true on the dropdownlist in order to be firing this event. There is no logical reason for it not to fire when any change is made, providing that the dropdownlist is populated correctly and the selectedindexchanged event should be fired when the page is posted back.
TimCottee
ASKER
here is my ddl
<asp:DropDownList ID="ddl" runat="server" Width="225px" AutoPostBack="True" OnSelectedIndexChanged="dd l_Selected IndexChang ed">
</asp:DropDownList>
So you can see that the autoPostBack is enabled.
Is it supposed to fire ? when first item re-selected or it suppose not? i am lost
<asp:DropDownList ID="ddl" runat="server" Width="225px" AutoPostBack="True" OnSelectedIndexChanged="dd
</asp:DropDownList>
So you can see that the autoPostBack is enabled.
Is it supposed to fire ? when first item re-selected or it suppose not? i am lost
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, TIm your answers inpired me that i am doing something else wrong .. so problem fixed now i used your help to come up with the bug fixed
This is why you very often see something like ' - Select a **** - ' as the first item in a dropdownlist. Because the initially selected item does not fire the onchange event you need to provide a mechanism that forces the user to choose one of your items.
Even if this is a databound list it is easy to do, when you have bound the dropdown then simply use:
mydropdownlist.Items.Inser
For example.
Regards,
TimCottee