10 Replies - 2795 Views - Last Post: 20 July 2012 - 05:16 AM Rate Topic: -----

#1 Memsey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 11-July 12

Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 12:00 PM

I have a drop down box with a load of ingedients in e.g. 'carrots', 'garlic'. The final item is 'other'.

If the user selects 'other' at runtime I would like a text box to appear that they can type a new item into (the item doesnt have to be added to the list. I just want the new text box to appear)

I thought using the selectedindexchanged command for the drop down list would make this work.

I tried using the following code:

Protected Sub DropDownListIngredients_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownListIngredients.SelectedIndexChanged

If DropDownListIngredients.SelectedValue = "other" Then
txtOther.visible = true
End If

End Sub



I have had no luck with the above code. Could anyone shed some light on how the above could be achieved in vb.net?

Any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Make a textbox appear when a certain value in dropdownlist is selected

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 12:22 PM

I take you mean a combo box? if so have a look at below:

If ComboBox1.SelectedItem.ToString = "Other" Then
            txtRate.Visible = True
        Else
            txtRate.Visible = False
        End If

Was This Post Helpful? 0
  • +
  • -

#3 Memsey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 11-July 12

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 12:41 PM

Sorry I mean dropdownlist. Where would you place the code you have written above? within selectedindexchanged?
Was This Post Helpful? 0
  • +
  • -

#4 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 12:49 PM

Yeah i put it in the SelectedIndexChanged event
Was This Post Helpful? 0
  • +
  • -

#5 Memsey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 11-July 12

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 01:01 PM

can you show me your complete code please because I have tried doing what you've said and nothing happens at run time. Only way I've managed to get something to work is by checking the selected value once a button is clicked. But I want it to just happen automatically without use of a button.
Was This Post Helpful? 0
  • +
  • -

#6 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 01:52 PM

Hey this code is for a combo box as i don't have a drop down list in my vs 2010 controls

    Private Sub test(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedItem.ToString = "Other" Then
            txtRate.Visible = True
        Else
            txtRate.Visible = False
        End If
    End Sub

Was This Post Helpful? 0
  • +
  • -

#7 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,470
  • Joined: 07-April 08

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 02:26 PM

Is this a web application or a windows forms application? If I remember correctly a Windows Forms application uses a combo box while a web application uses a dropdownlist. If it is a web application check to make sure that the Autopostback property of your dropdownlist is set to true.

This post has been edited by rgfirefly24: 19 July 2012 - 02:28 PM

Was This Post Helpful? 1
  • +
  • -

#8 Memsey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 11-July 12

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 03:48 PM

Its a web app. Changing Autopostback to true works a charm. Thanks buddy!!
Was This Post Helpful? 0
  • +
  • -

#9 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 19 July 2012 - 04:26 PM

2 minuses because you forgot to tell me! it was a web app tu tu
Was This Post Helpful? 0
  • +
  • -

#10 Memsey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 11-July 12

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 20 July 2012 - 05:12 AM

Isn't vb.net used only for web apps?

The reason I voted your comments down was because they didn't help answer my question - you can see in my original code i'm using a drop down list and not a combo box. no hard feelings buddy as the problem is solved now. thanks anyways for taking the time to look at it.
Was This Post Helpful? 0
  • +
  • -

#11 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,470
  • Joined: 07-April 08

Re: Make a textbox appear when a certain value in dropdownlist is selected

Posted 20 July 2012 - 05:16 AM

yes, VB.NET is used for web apps; however, the VB.NET forums sees I would say 90% of questions being about desktop applications. You might get better advice posting in the ASP.NET forums for your web app questions.

This post has been edited by rgfirefly24: 20 July 2012 - 05:16 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1