Databound Dropdown List and validation

R

Ric Castagna

Hello, all...

I'm trying to do a client-side validation on a databound dropdown
list.

All I want to do is check to see if the selected index is greater than
0 - an invalid option.

Here's the code I'm using, but I don't think the compare validator is
the right validation method to use. It, unfortunately, always thinks
there's an error.

<asp:dropdownlist id="ddlCategories" cssclass="adminText"
datatextfield="cat_desc" datavaluefield="cat_id" runat="server" />
<asp:comparevalidator id="cvCategories" operator="LessThan"
controltovalidate="ddlCategories" valuetocompare="1"
errormessage="Please select a category for this clip."
display="Dynamic" runat="server" />

I can't seem to find any postings on using validation against dropdown
lists on the client side, and I'd prefer to keep the validation there
as sending it server-side would really junk up the works.

Please help.

Thanks!
 
T

Teemu Keiski

Hi,

you can use RequiredFieldValidator for it, just set the InitialValue
property to the value of the first item in the DDL (the invalid one) and it
will then ensure that correct selection is made.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top