DropDownList
Admin
DropDownList
Property | Description |
SelectedIndex | Index of the item selected |
- Open Visual Studio
- Add a new webform call it DropDownList.aspx
- Add a dropDownlist and name it ddlState
- Add a label control and name it lblDisplay
- Select the smart tag on the dropdownlist
- Check the enable AutoPostBack
- Select Edit Items
- Click Add
- Change the text to Pick your state
- Leave the value blank
- Click Add again
- Enter Ohio in the text and OH in the value
- Add three more
- Florida Fl
- California CA
- Kentucky KY
- Click OK
- Test it
- Double-click the page and add this code to the page_load
1 | If ispostback then |
2 | If ddlState.SelectedIndex=0 then |
3 | lblDisplay.text="You did not select anything" |
4 | else |
5 | lblDisplay.text="State: " & ddlState.SelectedItem.text & "<br />" |
6 | lblDisplay.text+="Abbrev: " & ddlState.SelectedItem.value & "<br />" |
7 | lblDisplay.text+="SelectedIndex: " & ddlState.SelectedIndex |
8 | end if |
9 | end if |