Question

I want to execute a query when a user chooses from a dropdown box, I know it can be done in jquery with the onchange function but I am not sure how to perform it using vb.net

Any ideas on how to do it? or is this even possible in vb.net?

I am using microsoft visual basic 2008 express edition.

Was it helpful?

Solution

In ASP.NET, you can use onselectedindexchanged event, similar to the SelectedIndexChanged of winforms:

<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True" 
     onselectedindexchanged="myFunction">
</asp:DropDownList>

In your code behind:

Protected Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged
     'Your logic here
End Sub

Update:

In winforms, you can use SelectedIndexChanged, but I suggest SelectionChangeCommitted event in order to fire the event if the user is really the one who changed the selections.

Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
    'Your code goes here...
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top