how to raise SelectedIndexChange event?

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hello,

I'm starting with asp.net and i don't know how to raise the
SelectedIndexChange event when clicking in a dropdownlist control.
I thought it was the same as by clicking on a button.

This is what i did:
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

In the code-behind:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
response.write("test ok")
end sub

But nothing happens when clicking in the dropdownlist.
I probably miss some code ...

Any help woul be appreciated
Dave
 
you can do that in two ways:
the simplest ( using the Design View )
click one time in the DropDownList, in Properties Window there is a
orange lighting icon (Events), click it
then you can see what events can you add to that components (in this
case the DropDownList)
to add a event click twice in one of then...
writting code ( using the Code View )
your code is actualy almost done, except that you miss one important
thing and one less important but for what you wan to do, extermelly
important.

your code is:
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

as you can see, you are not telling the component to do anything! so you
need to tell him that you want to perform a function and if you want to
perform such function everytime you change the options in the DropDown you
need to tell him to perform an autopostbask, so the correct code will be
like this:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
OnSelectIndexChange="DropDownList1_SelectedIndexChanged"></asp:DropDownList>

you can remove the Handles DropDownList1.SelectedIndexChanged from the
function if you add the OnSelectIndexChange, or keep it and remove the event
from the ddl compont

hope that helps.
 
Thanks for replying, but my mistake was that the option "autopostback" was
set on "off" in the properties. I changed it to "on" and it works ...
 
Back
Top