473,836 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2250
"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 myClientValidat ionFunction(obj Sender, 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:customvali dator runat=server id="myCustomVal idator"
clientvalidatio nfunction="myCl ientValidationF unction" ErrorMessage="M y Error
Message">*</asp:customvalid ator>
....

By doing this, you will be able to client side validate that the selected
items are valid. Do not forget to implement the
myCustomValidat or.ServerValida te 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5631
by: mike | last post by:
How do i do the following: lbCountries.SelectedValue = "826"; lbCountries.SelectedValue = "840"; Basically i've set the selectmode to multiple and want to select multiple values of the listbox on databind. the problem is this only selects the last row "840" -- i would imagine this
2
2066
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
2
2737
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the second one. I seem unable to do this as it only sends back the first item I select whether I have the CTL key down or not. Upon the return trip, I can select another one, but it still only sends value for the last one I selected. -- MY LISTBOX --...
10
6397
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but still error occurs. I need information on this. Thanks. Ads
1
3196
by: karups | last post by:
Hi, I've got listbox in my .aspx page where the users can make multiple selection. So, Users can select 7 items in listbox, I have to take value from items and pass it to stored procedure to extract a dataset back. 1.What should i do while passing the multiple selected values 2.Can i use 'in' clause in SQL procedure like eg:Select a.xxx from a where a.yyy in @y
1
1440
by: colleen1980 | last post by:
Hi: I am trying to pull all the values from the listbox. But the ASP code shows only the last record. Needs help HTML <html> <head>
1
2770
by: Marisa | last post by:
Hi. I am new to C#, and I am having trouble getting the multiple selection of listbox to work. I have an asp.net web form, and I need two listboxes which are filled with an access table. I have to be able to select multiple items, and fill a datagrid with the results. I can fill 2 listboxes and a datagrid, but not with multiple selections. So far, I have no code behind, I have completed it with just using the characteristics of the...
2
6953
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've come across a way to set the listbox value to only 1 at a time, but need multiple toggle buttons to be on their corresponding listbox item values to be selected. Thanks!
45
6900
by: angelicdevil | last post by:
i have 2 tables 1 is status_type with field name status and other is users with field username and status now i want that the first listbox lists all status from status type ( this i have achieved with php ) and based on selection of the value in listbox 1 the corresponding data in table users be loaded in listbox 2 . i have achieved this by using a button in php but i want tht it operate without submit button and no page refreshing ...
0
9812
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10532
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.