469,631 Members | 1,328 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Help with Multiple Select ListBox

sab
Hi,
We have a web form with a listbox. The listbox is a multiple select listbox
and has data that looks something like:

ALL
Unit 1
Unit 2
Unit 3

Note: "ALL" is always the first item in the list.

Anyway, ALL can be selected, but only if it is the only item selected (i.e.,
an invalid selection would be to select ALL and Unit 1). The other "Unit"
items can be selected by themselves or with multiple "Unit" items (e.g.,
Unit 1, or Unit 2 and Unit 3, etc.). The validations are:

If ALL and no Unit items selected, then valid
If ALL and one or more Unit items selected, then invalid
If one or more Unit items selected (without ALL being selected), then valid

We're having trouble figuring out how to validate that the user selected a
valid set of items.

Can anyone be of assistance? How do we write the code to validate this
situation? In what event should the code be placed? Etc?

Thanks in advance.
Nov 19 '05 #1
1 2072
"sab" wrote:
Hi,
We have a web form with a listbox. The listbox is a multiple select listbox
and has data that looks something like:

ALL
Unit 1
Unit 2
Unit 3

Note: "ALL" is always the first item in the list.

Anyway, ALL can be selected, but only if it is the only item selected (i.e.,
an invalid selection would be to select ALL and Unit 1). The other "Unit"
items can be selected by themselves or with multiple "Unit" items (e.g.,
Unit 1, or Unit 2 and Unit 3, etc.). The validations are:

If ALL and no Unit items selected, then valid
If ALL and one or more Unit items selected, then invalid
If one or more Unit items selected (without ALL being selected), then valid

We're having trouble figuring out how to validate that the user selected a
valid set of items.

Can anyone be of assistance? How do we write the code to validate this
situation? In what event should the code be placed? Etc?

Thanks in advance.


You may want to try to use a custom validator. It would be someting like:

....
<script>

function myClientValidationFunction(objSender, objArgs) {
// Write your implementation here using javascript

// If ALL and no Unit items selected, then valid
objArgs.IsValid = true;
// If ALL and one or more Unit items selected, then invalid
objArgs.IsValid = false;
// If one or more Unit items selected (without ALL being selected), then
valid
objArgs.IsValid = true;
};

</script>
....
<asp:listbox runat=server id=myListBox multiple=true />
....
<asp:customvalidator runat=server id="myCustomValidator"
clientvalidationfunction="myClientValidationFuncti on" ErrorMessage="My Error
Message">*</asp:customvalidator>
....

By doing this, you will be able to client side validate that the selected
items are valid. Do not forget to implement the
myCustomValidator.ServerValidate function and ask "If Page.IsValid" before
doing anything as well.

Should you have any questions or comments, let me know

Regards,
Cesar Saucedo
Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Daniel | last post: by
2 posts views Thread by DC Gringo | last post: by
10 posts views Thread by ads | last post: by
1 post views Thread by Marisa | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.