Hi to all
I have an drop down list, in that there are two fields one is income, expenses and text box . If i select income from the dropdown list then the text box should be disabled, if i select expenses then the textbox should be enabled.

I have tried using this code.
My code
Protected Sub type_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles type.SelectedIndexChanged
If type.SelectedValue.ToString = "Income" Then
vc.Enabled = False
Else
vc.Enabled = True
End If
End Sub

you should enable autopostback for the dropdown list otherwise it wont work.
If you need to run it on a client side then use javascript.

Thank you
Khaled

I'd also point out that in your code you have both code paths setting the control to Enabled rather than one changing it to Disabled. Possibly a typo in your post, possibly in your actual code, so I thought I'd mention it.

Hi to all
I have an drop down list, in that there are two fields one is income, expenses and text box . If i select income from the dropdown list then the text box should be disabled, if i select expenses then the textbox should be enabled.

I have tried using this code.
My code
Protected Sub type_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles type.SelectedIndexChanged
If type.SelectedValue.ToString = "Income" Then
vc.Enabled = False
Else
vc.Enabled = True
End If
End Sub

Try this

Protected Sub type_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles type.SelectedIndexChanged
If type.Text = "Income" Then
vc.Enabled = False
Else
vc.Enabled = True
End If
End Sub

Try this

Protected Sub type_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles type.SelectedIndexChanged
If type.Text = "Income" Then
vc.Enabled = False
Else
vc.Enabled = True
End If
End Sub

No, the code he has written is perfectly right, and the event he is firing is a server side event which will work after page being processed to the server, thats why Autopostback is needed for combobox.

Khaled

This article has been dead for over six months. Start a new discussion instead.