Ken Cox [MS MVP]
2/21/2004 2:33:00 AM
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" <mel_dev@comcast.net> wrote in message
news:925cfed9.0402201240.4ee2d6f@posting.google.com...
> 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.