How to create a drop-down selector which displays options from a SQL Server table in Visual Studio

Home > Search > How-to
  by

Follow these directions to create a drop-down selector which displays options from a SQL Server table in Visual Studio.

  1. In Visual Studio, drag the DropDownList object from Toolbox into Design View.
  2. In the DropDownList object menu, check-mark Enable AutoPostBack.
  3. Click Edit Items. In the ListItem Collection Editor pop-up box, click the Add button. In the Text field, type Select an Option. Delete any text displayed in the Value field. Click OK.
  4. In the markup, add value="" to the asp:Listitem.
<asp:ListItem value=\"\">Select an Option</asp:ListItem>
  1. Click Choose Data Source. 
  2. In the Data Source Configuration Window pop-up box, change the Select a data source drop-down to New data source.
  3. Highlight SQL Database. Make note of the data source name. Click OK.
  4. Select your connection string and click Next.
  5. Check-mark the column from your database you would like to appear in the drop-down.  Also check-mark the ID field. Click Next.
  6. For the Select a data field to display in the DropDownList, select the column from your database you would like to appear in the drop-down. For Select a data field for the value of the DropDownList, select ID. Click Finish.
  7. Click OK.

Press Ctrl F5 to tes this in your default Web browser.

  1. Drag a GridView object from Toobox into Design View.
  2. In the GridView object menu. select your data source name in the Choose Data Source drop-down.
  3. Select Edit Columns.
  4. In the Fields pop-up box, highlight HyperLinkField and click Add.
  5. Move HyperLinkField to the top of the Selected fields.


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments