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

>>thats why Autopostback is needed for combobox.

I thought it was drop down list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.