Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a dropdown edit/search box for my asp.net/c# website, the code now works fine but I want that when the selected index gets changed it would fire an event

This is the code I have got now
ASP.NET
<form  runat="server" id="form1">
        <div class="ui-widget">
            <asp:DropDownList ID="combobox" runat="server" AutoPostBack="true">
                <asp:ListItem Value="White" Selected="True">White</asp:ListItem>
                <asp:ListItem Value="Black">Black</asp:ListItem>
                <asp:ListItem Value="Blue">Blue</asp:ListItem>
            </asp:DropDownList>
        </div>
    </form>


I have tried multiple things to get this working, one of it is adding this:
HTML
OnSelectedIndexChanged="combobox_SelectedIndexChanged1"


The event does not fire at all but sometimes only after hitting Enter, I need it to fire when the index gets changed.
I don't know if I am doing this wrong or if there just isn't a way..
Can some please help me to find a solution
Thank You,

EDIT:
I added the EnableViewState, I am not sure what that is meant to do, but after putting my break point.. i can clearly see that when I click on another item from the drop downlist it doesn't fire the event because it doesn't go into this onSelectedIndexChanged code block.. I am so confused to why this is not working
Posted
Updated 11-Nov-13 22:19pm
v5
Comments
Orcun Iyigun 12-Nov-13 3:51am    
If you add that OnSelectedIndexChanged event to your dropdown it should work? Which browser are you trying it? IE?
Member 10395722 12-Nov-13 4:12am    
I was trying this code in Chrome, the latest version

Well from your markup I see it is lacking the event:
C#
<asp:dropdownlist id="combobox" runat="server" autopostback="true" enableviewstate="true" onselectedindexchanged="combobox_SelectedIndexChanged" xmlns:asp="#unknown">
   <asp:listitem value="White" selected="True">White</asp:listitem>
   <asp:listitem value="Black">Black</asp:listitem>
   <asp:listitem value="Blue">Blue</asp:listitem>
</asp:dropdownlist>

In your code behind:
C#
protected void combobox_SelectedIndexChanged(object sender, EventArgs e)
{
   //Do stuff
}


This should work.

Good luck,
OI
 
Share this answer
 
Comments
Member 10395722 12-Nov-13 4:55am    
Im sorry for being an iritation, I have put the event in, it works now but only after selecting an item and then hitting enter?
Vishal Pand3y 12-Nov-13 5:54am    
this is what Dropdown is Supposed to do
when you change the selected value in dropdown then the code of selected index changed fires....
put Some break points on selected index changed code and see whether it is compiling or not ...
 
Share this answer
 
v2
Comments
Vishal Pand3y 12-Nov-13 4:28am    
check combobox_SelectedIndexChanged1 and code on which you have put break points are same or not
i am saying that because 1 after name confused me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900