Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnSelectedIndexChanged not working for me

Status
Not open for further replies.

sunil128

Programmer
Mar 20, 2008
45
GB
Hi all, another newbie question, i am using Visual Studio 2005 (ASP.NET 2.0) and C# and i am having a problem using the OnSelectedIndexChanged method and the SelectedIndexChanged method.

Basically when i change the the drop down list nothing happpens and it doesnt even go into the DropDownList1_SelectedIndexChanged code (below). Can anyone tell my why this is happening??

My C# code is as follows
Code:
       protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            Populate(1);
        }

My ASP code is like this
Code:
        <asp:DropDownList ID="DropDownList1" runat="server" Width="131px" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
 
I didn't think the markup was case sensative, but maybe it is. try OnSelectedIndexChanged. also step through your code to ensure it is working properly. other than that it looks good. if you continue to have this problem delete the control/page and start over.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for your reply Jason, the reason onselectedindexchanged is in lower case is becasue i was experimenting as it wasnt working with uppercase leading characters either.

Also i was actually refering to stepping thru the code when i said it doesnt even go into the DropDownList1_SelectedIndexChanged. its like it doesnt even recognise the DropDownList1_SelectedIndexChanged event. Although i havent stepped thru the ASP code yet to see if there is an issue with the onselectedindexchanged event.
 
Also why do some of my refernces to SelectedIndexChanged sometimes have a one on the end? e.g.

DropDownList1_SelectedIndexChanged1
 
Did you create the event declaration programatically as well as using the designer?
 
To be honest jbenson001, i am very mush an ASP/VS/C# newbie and so i copied & pasted the C# from another part of the application where it was already working, but i did not copy the ASP code as that (i assume) was automatically generated.

Can i be very stupid and ask exactly what you mean when you say "did i create the event declaration programatically as well as using the designer?
 
You can create the event declaration in code OR you can use the designer(in the code view) to generate the event declaration for you. There are 2 dropdowns, the one on the left has the controls that are on the page, and the right one has all the events that are assocated with the control selected on the left. Once you choose the event, it will place the event declaration in the code behind for you.
 
Hi jbenson001 i tried deleting my controls and starting again.

Were you refering the C# coding window when you spoke about the designer view? Because after creating the control, only the control is listed in left hand dropdown i.e. DropDownlist1 - but no associated events.

And in the right hand dropdown it only has the module im currently working on i.e. Property.CallLogEnquiry.
 
I have to ask (and maybe you just posted a snippet of code)... how are you even calling the SelectedIndexChange with no items in the control?
 
Do you show all the DropDown list declaration? If yes, where is the Source for the data? When you come to the page, is the Drop Down populated?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top