DropDownLists

M

Mirnes

Hi all!

In one page I have 5 dropdown lists since I want to be able to add one
company into max. 5 different categories but also to choose only one
category, and there I came to the problem: I want those categories to
be different. Ok, I used CompareValidator and it is not problem, but
then I added new static item into every dropdown with value "-1" and
text "Select category" and now I have problem because Validator finds
that dropdown values are the same and blocks addition.

The best solution for me is that I remove item which is selected in
one dropdown list from other 4 dropdown lists or at list to make
Validator not checks values < 0, but I don't know how to make any of
these 2 solution.
 
G

Guest

Hi all!

In one page I have 5 dropdown lists since I want to be able to add one
company into max. 5 different categories but also to choose only one
category, and there I came to the problem: I want those categories to
be different. Ok, I used CompareValidator and it is not problem, but
then I added new static item into every dropdown with value "-1" and
text "Select category" and now I have problem because Validator finds
that dropdown values are the same and blocks addition.

The best solution for me is that I remove item which is selected in
one dropdown list from other 4 dropdown lists or at list to make
Validator not checks values < 0, but I don't know how to make any of
these 2 solution.

Well, I think you will need 5 CustomValidator Controls.

Example

<asp:CustomValidator Id="cv1"
ControlToValidate="DropDownList1"
Text="Category is not unique!"
OnServerValidate="DropDownList1_ServerValidate"
ClientValidationFunction="DropDownList1_ClientValidate"
Runat="server" />

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="" Value=""></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:DropDownList>

....

Here's a code of a client-side validation function with the first
CustomValidator control.

<script type="text/javascript">

function DropDownList1_ClientValidate(source, args)
{
var DropDownList1 = document.getElementById("DropDownList1");
var DropDownList2 = document.getElementById("DropDownList2");
....

if (DropDownList1.selectedIndex == 0 || (DropDownList1.selectedIndex !
= DropDownList2.selectedIndex ...))
{
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>

function DropDownList2_ClientValidate(source, args)
{
....
}

....
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top