473,756 Members | 5,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

listbox - mulitple selection detection

I have an asp:listbox, allowing multiple selections, is there a quick check
to see if there's more than one selected, or do I need to go through the
whole list?

Thanks, Dave
Nov 19 '05 #1
5 2315
Dave H <Da***@noemail. nospam> ha scritto:
I have an asp:listbox, allowing multiple selections, is there a quick
check to see if there's more than one selected, or do I need to go
through the whole list?

Thanks, Dave


This is possibile solution:
int
selected=Reques t.Params[ListBox1.Client ID]==null?0:Reques t.Params[ListBox1.Client ID].ToString().Spl it(',').Length;

if (selected>1)
// multi-select

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az

Nov 19 '05 #2
Thanks for Andrea's inputs.

Hi Dave,

Since the ASP.NET ListBox dosn't provide buildin property to represent
multi selected items(under multi-select mode), generally we need to loop
through all the items to check the selection status.

Also, I think Andrea's suggestion is a good trick since it directly capture
the ListBox's html post back datas and analyize it to get whether there's
multi items selected. One correction on the code is that we should use the
"UniqueID" rather than "clientID" when retrieving control's postback form
data. For example:

Request.Form[this.ListBox1.U niqueID]

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Andrea Zani" <an****@aspital ia.com>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| References: <PK************ *************** **************@ comcast.com>
| Subject: Re: listbox - mulitple selection detection
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-Antivirus: avast! (VPS 0532-6, 13/08/2005), Outbound message
| X-Antivirus-Status: Not-Tested
| Message-ID: <AI************ ********@twiste r2.libero.it>
| Date: Sun, 14 Aug 2005 08:58:08 GMT
| NNTP-Posting-Host: 151.47.29.112
| X-Complaints-To: ab***@net24.it
| X-Trace: twister2.libero .it 1124009888 151.47.29.112 (Sun, 14 Aug 2005
10:58:08 MET DST)
| NNTP-Posting-Date: Sun, 14 Aug 2005 10:58:08 MET DST
| Organization: [Infostrada]
| Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!newsf e
ed01.sul.t-online.de!t-online.de!nntp. infostrada.it!t wister2.libero. it.POSTE
D!not-for-mail
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1178 58
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Dave H <Da***@noemail. nospam> ha scritto:
| > I have an asp:listbox, allowing multiple selections, is there a quick
| > check to see if there's more than one selected, or do I need to go
| > through the whole list?
| >
| > Thanks, Dave
|
| This is possibile solution:
| int
|
selected=Reques t.Params[ListBox1.Client ID]==null?0:Reques t.Params[ListBox1.C
lientID].ToString().Spl it(',').Length;
|
| if (selected>1)
| // multi-select
|
| --
| AZ [Microsoft - .NET MVP]
| Mia Home page: http://ciclismo.sitiasp.it
| Asp.Net community: http://www.aspitalia.com
| Il mio blog: http://blogs.aspitalia.com/az
|
|
|
|

Nov 19 '05 #3
Steven Cheng[MSFT] <st*****@online .microsoft.com> ha scritto:
Request.Form[this.ListBox1.U niqueID]


Thanks for your correction, Steven.

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
Nov 19 '05 #4
Thanks, to both of you... Dave

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:pq******** *****@TK2MSFTNG XA01.phx.gbl...
Thanks for Andrea's inputs.

Hi Dave,

Since the ASP.NET ListBox dosn't provide buildin property to represent
multi selected items(under multi-select mode), generally we need to loop
through all the items to check the selection status.

Also, I think Andrea's suggestion is a good trick since it directly capture the ListBox's html post back datas and analyize it to get whether there's
multi items selected. One correction on the code is that we should use the "UniqueID" rather than "clientID" when retrieving control's postback form
data. For example:

Request.Form[this.ListBox1.U niqueID]

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Andrea Zani" <an****@aspital ia.com>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| References: <PK************ *************** **************@ comcast.com>
| Subject: Re: listbox - mulitple selection detection
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Original
| X-Antivirus: avast! (VPS 0532-6, 13/08/2005), Outbound message
| X-Antivirus-Status: Not-Tested
| Message-ID: <AI************ ********@twiste r2.libero.it>
| Date: Sun, 14 Aug 2005 08:58:08 GMT
| NNTP-Posting-Host: 151.47.29.112
| X-Complaints-To: ab***@net24.it
| X-Trace: twister2.libero .it 1124009888 151.47.29.112 (Sun, 14 Aug 2005
10:58:08 MET DST)
| NNTP-Posting-Date: Sun, 14 Aug 2005 10:58:08 MET DST
| Organization: [Infostrada]
| Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!newsf e ed01.sul.t-online.de!t-online.de!nntp. infostrada.it!t wister2.libero. it.POSTE D!not-for-mail
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1178 58
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Dave H <Da***@noemail. nospam> ha scritto:
| > I have an asp:listbox, allowing multiple selections, is there a quick
| > check to see if there's more than one selected, or do I need to go
| > through the whole list?
| >
| > Thanks, Dave
|
| This is possibile solution:
| int
|
selected=Reques t.Params[ListBox1.Client ID]==null?0:Reques t.Params[ListBox1.C lientID].ToString().Spl it(',').Length;
|
| if (selected>1)
| // multi-select
|
| --
| AZ [Microsoft - .NET MVP]
| Mia Home page: http://ciclismo.sitiasp.it
| Asp.Net community: http://www.aspitalia.com
| Il mio blog: http://blogs.aspitalia.com/az
|
|
|
|

Nov 19 '05 #5
You're welcome.
Good Luck!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| NNTP-Posting-Date: Mon, 15 Aug 2005 21:48:02 -0500
| From: "Dave H" <Da***@noemail. nospam>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| References: <PK************ *************** **************@ comcast.com>
<AI************ ********@twiste r2.libero.it>
<pq************ *@TK2MSFTNGXA01 .phx.gbl>
| Subject: Re: listbox - mulitple selection detection
| Date: Mon, 15 Aug 2005 19:47:51 -0700
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <C9************ ********@comcas t.com>
| Lines: 91
| NNTP-Posting-Host: 67.180.218.69
| X-Trace:
sv3-pLUCskW8oRVJlJh N5TQ3G7OE2umQhd ZtlRz4BkSwOo6ML IYJqEQC1/Gvq3ntcijMF+Bpo uA8
svnPHi9!AIczeap VDTMhmkBezfj/yPnxqkQ2bhy09u3 4cr7Qae35ZBbfhz 8palfDS05MZPBIy oVi
q4MqXX90!8TAm
| X-Complaints-To: ab***@comcast.n et
| X-DMCA-Complaints-To: dm**@comcast.ne t
| X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
| X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
| X-Postfilter: 1.3.32
| Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTF EED02.phx.gbl!t ornado.fastwebn et.it!tiscali!n e
wsfeed1.ip.tisc ali.net!news.ma xwell.syr.edu!b order1.nntp.dca .giganews.com!l o
cal01.nntp.dca. giganews.com!nn tp.comcast.com! news.comcast.co m.POSTED!not-for
-mail
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1181 51
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thanks, to both of you... Dave
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:pq******** *****@TK2MSFTNG XA01.phx.gbl...
| > Thanks for Andrea's inputs.
| >
| > Hi Dave,
| >
| > Since the ASP.NET ListBox dosn't provide buildin property to represent
| > multi selected items(under multi-select mode), generally we need to loop
| > through all the items to check the selection status.
| >
| > Also, I think Andrea's suggestion is a good trick since it directly
| capture
| > the ListBox's html post back datas and analyize it to get whether
there's
| > multi items selected. One correction on the code is that we should use
| the
| > "UniqueID" rather than "clientID" when retrieving control's postback
form
| > data. For example:
| >
| > Request.Form[this.ListBox1.U niqueID]
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "Andrea Zani" <an****@aspital ia.com>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | References: <PK************ *************** **************@ comcast.com>
| > | Subject: Re: listbox - mulitple selection detection
| > | Lines: 22
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| > | X-RFC2646: Format=Flowed; Original
| > | X-Antivirus: avast! (VPS 0532-6, 13/08/2005), Outbound message
| > | X-Antivirus-Status: Not-Tested
| > | Message-ID: <AI************ ********@twiste r2.libero.it>
| > | Date: Sun, 14 Aug 2005 08:58:08 GMT
| > | NNTP-Posting-Host: 151.47.29.112
| > | X-Complaints-To: ab***@net24.it
| > | X-Trace: twister2.libero .it 1124009888 151.47.29.112 (Sun, 14 Aug 2005
| > 10:58:08 MET DST)
| > | NNTP-Posting-Date: Sun, 14 Aug 2005 10:58:08 MET DST
| > | Organization: [Infostrada]
| > | Path:
| >
|
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!newsf e
| >
|
ed01.sul.t-online.de!t-online.de!nntp. infostrada.it!t wister2.libero. it.POSTE
| > D!not-for-mail
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1178 58
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | Dave H <Da***@noemail. nospam> ha scritto:
| > | > I have an asp:listbox, allowing multiple selections, is there a
quick
| > | > check to see if there's more than one selected, or do I need to go
| > | > through the whole list?
| > | >
| > | > Thanks, Dave
| > |
| > | This is possibile solution:
| > | int
| > |
| >
|
selected=Reques t.Params[ListBox1.Client ID]==null?0:Reques t.Params[ListBox1.C
| > lientID].ToString().Spl it(',').Length;
| > |
| > | if (selected>1)
| > | // multi-select
| > |
| > | --
| > | AZ [Microsoft - .NET MVP]
| > | Mia Home page: http://ciclismo.sitiasp.it
| > | Asp.Net community: http://www.aspitalia.com
| > | Il mio blog: http://blogs.aspitalia.com/az
| > |
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6196
by: Jack | last post by:
Hi guys, I've searched and search... everyone talks about the multiselect listbox control they have. BUT... how the hell do I implement it in the first place. Do I just have to turn on a standard reference? Do I have to download an active X? And whats the name of it in the "More Controls" list. Thanks for any help
2
6808
by: (Pete Cresswell) | last post by:
Seems like I've been here before, but can't find anyting in Google. I've got two list boxes on a form. Seems to me like the inactive ListBox's selection rectangle should be something like gray...otherwise, the user sees two ListBoxes, both with black selection rectangles - and the user does not visually know which one he is "in". This becomes relevant if we have a keyboard-type user - they want to hit "Enter" and have something...
6
30026
by: Dan Bass | last post by:
If you look at explorer, right clicking on a file, first selects the file, then throws up the context menu relating to that selection. With a Windows ListBox control and a simple context menu, the default behaviour seems to display the context menu on the listbox, but there is no selection. Now I know that explorer's using a listview, and that the context menu acts differently if you click on open space (no selection), but can I...
6
12918
by: Alpha | last post by:
I have a listbox with datasource from a dataview. When a user selects a different item in a combobox then I need to refresh the listbox to the appropriate listing based on that combobox's selected value which is included in the listbox's filtering statement. Is the only way to do this is to dispose the dataview and then create a new one and then bind it to the listbox? Is there a better way than this? Thanks, Alpha
6
2879
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
0
1343
by: Sanjin | last post by:
I have populated listbox with data from the datatable. I binded SelectedValue to the another datatable - i.e. selection result (with VS 20005 wizard). Selection result datatable has one column with type Int32.
9
3248
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this selection. I am using an SQLDataSource web control for this. These items are headers. I want, when...
8
1887
by: Mike | last post by:
I'm passing an array to a listbox such as (1,2,3,4,5,6,7), I want to highlight (select) all the items in the listbox were the value equals (1,2,3,4,5,6,7). I'm able to only get the last value selected, how can I get all of them selected? The listbox selectionMode= mulitple for (int i = 0; i < Id.Length; i++) { CarList.SelectedValue = Id;
4
1455
by: kimiraikkonen | last post by:
Hi, I have a odd but a known question about listbox. I know listbox control can provide multi-select, multi-extendend selections. But i wonder if this selection type belongs to them or it has another tecnique. As you may know, in softwares like Windows Media Player or Winamp playlist has a listbox and it can be selected in 2 types. First type refers to player's own selection and second selection type can be done by user to look for...
0
10069
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...
1
9884
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
9735
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...
0
6556
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
5168
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
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
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
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
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.