call OnSelectedIndexChanged??

G

Guest

Does somebody knows, if there's a way to call the OnSelectedIndexChanged method of the dropdownlist by myself?

Or does somebody knows a way, to raise the SelectedIndexChanged Event of a dropdownlist?

tia
Martin
 
K

Ken Cox [Microsoft MVP]

Hi Martin,

You should be able to call the subroutine on your own as long as you pass
the parameters it expects.

Here's a way to do it on a button click:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim earg As New EventArgs
Call DropDownList1_SelectedIndexChanged _
(DropDownList1, earg.Empty)
End Sub

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Button1.Text = _
DropDownList1.SelectedValue.ToString
End Sub

<P>
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp:DropDownList></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>

Is this what you meant?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
G

Guest

Thx for the reply but this is not what I mean, the problem is much more complicated.
I have the object of the dropdownlist, but I don't know how the eventhandler is called.

I am in a class outside of the page of the dropdownlist !

Ken Cox said:
Hi Martin,

You should be able to call the subroutine on your own as long as you pass
the parameters it expects.

Here's a way to do it on a button click:

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim earg As New EventArgs
Call DropDownList1_SelectedIndexChanged _
(DropDownList1, earg.Empty)
End Sub

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Button1.Text = _
DropDownList1.SelectedValue.ToString
End Sub

<P>
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp:DropDownList></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>

Is this what you meant?

Ken
Microsoft MVP [ASP.NET]
Toronto


Martin said:
Does somebody knows, if there's a way to call the OnSelectedIndexChanged
method of the dropdownlist by myself?

Or does somebody knows a way, to raise the SelectedIndexChanged Event of a
dropdownlist?

tia
Martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top