by Jeremy Canfield | Updated January 1st, 2017
Follow these directions to create a drop-down selector which displays options from a SQL Server table in Visual Studio.
- In Visual Studio, drag the DropDownList object from Toolbox into Design View.
- In the DropDownList object menu, check-mark Enable AutoPostBack.
- 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.
- In the markup, add value="" to the asp:Listitem.
<asp:ListItem value=\"\">Select an Option</asp:ListItem>
- Click Choose Data Source.
- In the Data Source Configuration Window pop-up box, change the Select a data source drop-down to New data source.
- Highlight SQL Database. Make note of the data source name. Click OK.
- Select your connection string and click Next.
- Check-mark the column from your database you would like to appear in the drop-down. Also check-mark the ID field. Click Next.
- 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.
- Click OK.
Press Ctrl F5 to tes this in your default Web browser.
- Drag a GridView object from Toobox into Design View.
- In the GridView object menu. select your data source name in the Choose Data Source drop-down.
- Select Edit Columns.
- In the Fields pop-up box, highlight HyperLinkField and click Add.
- Move HyperLinkField to the top of the Selected fields.