Forum Moderators: open
For example, if I want to execute something but only if there was NO selection in my DropDownList control, what would I have to target? The "SelectedItem.Value" or the "ddlLang.SelectedIndexChanged" event? I'm very new to this but I tried something along these lines
if (MyDropDown.SelectedItem.Value -= 0){
//Do something}
But I get the following error:
Operator '-=' cannot be applied to operands of type 'string' and 'int'
Then I tried the following:
if (!MyDropDown.SelectedIndexChanged){
//Do Something}
And got the following error:
The event 'System.Web.UI.WebControls.ListControl.SelectedIndexChanged' can only appear on the left hand side of += or -=
I'm obviously using the wrong syntax or something, could someone please clarify me on this?
Thanks
You need to set the "AutoPostBack" property of the control to true in the ASPX file - something like this...
<asp:DropDownList id="MyDropDown" Runat="server" AutoPostBack="true"></asp:DropDownList>
... then in the VB file, you need to create an event handler function which will get fired each time the user selects something...
Private Sub MyDropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyDropDown.SelectedIndexChanged
End Sub
In this function, you can then check what the value of the user's selection is with this line of code...
if (MyDropDown.SelectedValue = 0) then
end if
... hope that helps!
- Chris