Get ID/Value in one Sub handling multiple SelectedIndexChanged events?

Discussion in 'ASP .Net Web Controls' started by MLecrone, Feb 20, 2004.

  1. MLecrone

    MLecrone Guest

    Please pardon my ignorance if this is an obvious question to you more
    experienced .Netters! I'm sure it only has to do with referencing the
    right class (or containing object?), but I've been unsuccessful thus
    far.

    I have a single subroutine that handles multiple SelectedIndexChanged
    events:

    Private Sub SelectedIndexChanged(ByVal sender As System.Object, ByVal
    e As System.EventArgs) Handles ddlEmployeeType.SelectedIndexChanged,
    ddlEmployeeName.SelectedIndexChanged, ddlGroups.SelectedIndexChanged,
    ddlWorkCenter.SelectedIndexChanged, lstBuyers.SelectedIndexChanged

    Inside this Sub I would then like to discover which control raised the
    event along with the "selected index" of the control so that I can
    then manipulate a dynamic SQL statement to return appropriate data.

    The closest I've gotten so far is to grab sender.GetType.Name, but
    obviously I don't care that the sender was a drop down list, I already
    know that.

    Any help or pointing me to an appropriate reference is much
    appreciated.
    MLecrone, Feb 20, 2004
    #1
    1. Advertising

  2. Hi Mel,

    Although you have the Sender, you don't at that point know that it is a
    dropdownlist. Therefore, you can't get much information about it. The trick
    is to make an instance of a ddl and then get all kinds of info that you
    want. I've put a sample below.

    Let us know if this helps?

    Ken
    Microsoft MVP[ASP.NET]
    Toronto


    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles DropDownList1.SelectedIndexChanged, _
    DropDownList2.SelectedIndexChanged, _
    DropDownList3.SelectedIndexChanged
    Dim ddlTester As DropDownList
    ddlTester = sender
    Label1.Text = "Postback by: " & _
    ddlTester.ID & "<br>SelectIndex=" & _
    ddlTester.SelectedIndex.ToString & _
    "<br>Value=" & _
    ddlTester.SelectedItem.Value.ToString
    End Sub

    <form id="Form1" method="post" runat="server">
    <P>
    <asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem Value="red">red</asp:ListItem>
    <asp:ListItem Value="blue">blue</asp:ListItem>
    <asp:ListItem Value="green">green</asp:ListItem>
    </asp:DropDownList></P>
    <P>
    <asp:DropDownList id="DropDownList2" runat="server" AutoPostBack="True">
    <asp:ListItem Value="Top">Top</asp:ListItem>
    <asp:ListItem Value="Middle">Middle</asp:ListItem>
    <asp:ListItem Value="Bottom">Bottom</asp:ListItem>
    </asp:DropDownList></P>
    <P>
    <asp:DropDownList id="DropDownList3" runat="server" AutoPostBack="True">
    <asp:ListItem Value="Left">Left</asp:ListItem>
    <asp:ListItem Value="Centre">Centre</asp:ListItem>
    <asp:ListItem Value="Right">Right</asp:ListItem>
    </asp:DropDownList></P>
    <P>
    <asp:Label id="Label1" runat="server">Label</asp:Label></P>
    </form>


    "MLecrone" <> wrote in message
    news:...
    > Please pardon my ignorance if this is an obvious question to you more
    > experienced .Netters! I'm sure it only has to do with referencing the
    > right class (or containing object?), but I've been unsuccessful thus
    > far.
    >
    > I have a single subroutine that handles multiple SelectedIndexChanged
    > events:
    >
    > Private Sub SelectedIndexChanged(ByVal sender As System.Object, ByVal
    > e As System.EventArgs) Handles ddlEmployeeType.SelectedIndexChanged,
    > ddlEmployeeName.SelectedIndexChanged, ddlGroups.SelectedIndexChanged,
    > ddlWorkCenter.SelectedIndexChanged, lstBuyers.SelectedIndexChanged
    >
    > Inside this Sub I would then like to discover which control raised the
    > event along with the "selected index" of the control so that I can
    > then manipulate a dynamic SQL statement to return appropriate data.
    >
    > The closest I've gotten so far is to grab sender.GetType.Name, but
    > obviously I don't care that the sender was a drop down list, I already
    > know that.
    >
    > Any help or pointing me to an appropriate reference is much
    > appreciated.
    Ken Cox [Microsoft MVP], Feb 21, 2004
    #2
    1. Advertising

  3. MLecrone

    MLecrone Guest

    Ken, that looks to be exactly what I'm looking for! Thank you so much.
    I really didn't want to create a separate sub to address each drop
    down's SelectedIndexChanged events and this will ensure I don't have
    to! Thanks again for your time and information.
    MLecrone, Feb 21, 2004
    #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. loveNUNO
    Replies:
    2
    Views:
    884
    loveNUNO
    Nov 20, 2003
  2. S.T
    Replies:
    4
    Views:
    413
  3. Ben
    Replies:
    2
    Views:
    853
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    1,934
    Lawrence D'Oliveiro
    May 20, 2011
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    327
    Chris
    Aug 30, 2005
Loading...

Share This Page