By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 930 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Help with Multiple Select ListBox

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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.