In this tutorial we will show you how to create a dropdown list and how to add to it with user input. Having a dropdown list on a website is a great tool because it can save space and make the site look much cleaner and professional. For example, instead of having multiple links on a page, you can have a dropdown list that leads to links.

1. Open Microsoft Visual Studio.

2. Click File > New > Web Site.

3. Right click on the solution name in Solution Explorer and click Add New Item. Make sure Visual Basic is selected as the installed template. Select Web Form and leave the name at Default.aspx.

4. Inside the < div > tags enter new paragraphs tags by writing < p > < /p >.

5. Inside the < p > tags click, drag and drop a TextBox control in from the toolbox between those tags. After the closing textbox tag insert a break line by writing < br / >.

6. After the break tag, click drag and drop a Button from the toolbox. After the closing button tag insert a break line tag (< br / >). In the Text field of Button, change the text from Button to Add.

7. After the break line tag click, drag and drop a DropDownList from the toolbox.

8. In between the opening and closing DropDownList tags we are going to add items to the dropdown list. We do this by writing ., with the word in the quotations of Text being the item on the list.

9. While in Default.aspx, switch to Design view. Double click the button Add.

This takes us to Default.aspx.vb, the Visual Basic coding of the page. You should see a Button1_Click method. Inside that method we need to tell it to add what the user wrote in the text box into the dropdown list.

10. Inside the Button1_Click method, write DropDownList1.Items.Add (TextBox1.Text).

This line of code gets access to items in DropDownList1 and adds what is written in TextBox1 through the Add method.

Run the application and click on the dropdown list. There will be two items, Shenmue and Sonic Adventure. Now write anything in the text box and click Add. Now open the dropdown list again and you should see what you wrote on the list. Keep in mind this tutorial does not show how to validate data in the text box and duplicates in the dropdown list, so that will occur. Just grasp the basics of setting and adding to a dropdown list.

Download Source Files