954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Urgent please

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

usershan
Newbie Poster
4 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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

atal
Newbie Poster
24 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 
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
vbLegend
Newbie Poster
3 posts since Jul 2007
Reputation Points: 20
Solved Threads: 0
 

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

atal
Newbie Poster
24 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

>>thats why Autopostback is needed for combobox.

I thought it was drop down list.

arjunsasidharan
Practically a Posting Shark
826 posts since Aug 2006
Reputation Points: 347
Solved Threads: 13
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You