Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate a DropDownList using its SelectedIndex Value

Status
Not open for further replies.

nevets2001uk

IS-IT--Management
Jun 26, 2002
609
GB
I have a page with 4 DropDownList boxes and on submission would like to check that the user has chosen an item in each checkbox. They each have a default value at SelectedIndex 0 so I would imagine the best way is to check whether the SelectedIndex is more than 0. However, I’m not really sure how to do this. Would guess a custom validator is needed but have no idea how to check the value of the SelectedIndex.

Any advice on how to achieve this or a better method for validating the page would be fantastic.

Cheers,

Steve G (MCP)
 
Hi
You can do what you want using the required field validator. You simply set the InitialValue property of the validator to the default value of the drop down. Then, unless the user changes this, the validator will prevent post back.
HTH

Mark [openup]
 
Thanks. Hadn't seen that InitialValue property.

Cheers,

Steve G (MCP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top