how to raise SelectedIndexChange event?

Discussion in 'ASP .Net Web Controls' started by Dave, Jun 10, 2006.

  1. Dave

    Dave Guest

    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
     
    Dave, Jun 10, 2006
    #1
    1. Advertising

  2. 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.


    --

    Bruno Alexandre
    (a Portuguese in Københanv, Danmark)


    "Dave" <> escreveu na mensagem
    news:O8XO%...
    > 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
    >
    >
     
    Bruno Alexandre, Jun 10, 2006
    #2
    1. Advertising

  3. Dave

    Dave Guest

    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 ...

    "Bruno Alexandre" <> wrote in message
    news:%23bv%...
    > 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.
    >
    >
    > --
    >
    > Bruno Alexandre
    > (a Portuguese in Københanv, Danmark)
    >
    >
    > "Dave" <> escreveu na mensagem
    > news:O8XO%...
    > > 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
    > >
    > >

    >
    >
     
    Dave, Jun 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    2
    Views:
    7,849
  2. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    409
    Gabriel Genellina
    Feb 5, 2007
  3. ernest
    Replies:
    2
    Views:
    294
    Roy Smith
    Nov 14, 2010
  4. Jack Bates
    Replies:
    0
    Views:
    281
    Jack Bates
    May 2, 2011
  5. bvdp

    Raise X or Raise X()?

    bvdp, Mar 11, 2012, in forum: Python
    Replies:
    10
    Views:
    371
    Stefan Behnel
    Mar 12, 2012
Loading...

Share This Page