[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

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

mel_dev

2/20/2004 8:41:00 PM

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

Ken Cox [MS MVP]

2/21/2004 2:33:00 AM

0

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.

mel_dev

2/21/2004 8:00:00 PM

0

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.