473,909 Members | 4,189 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 2253
"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
5633
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
2070
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
2739
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
6399
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
3199
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
1443
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
2773
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
6956
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
6910
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
10035
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
11346
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
10919
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...
1
11046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10538
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8097
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5938
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
6138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4774
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

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.