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

listbox - mulitple selection detection

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


P: n/a
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=Request.Params[ListBox1.ClientID]==null?0:Request.Params[ListBox1.ClientID].ToString().Split(',').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

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

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****@aspitalia.com>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <PK*****************************************@comca st.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********************@twister2.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.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!newsfe
ed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.PO STE
D!not-for-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:117858
| X-Tomcat-NG: microsoft.public.dotnet.framework.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=Request.Params[ListBox1.ClientID]==null?0:Request.Params[ListBox1.C
lientID].ToString().Split(',').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

P: n/a
Steven Cheng[MSFT] <st*****@online.microsoft.com> ha scritto:
Request.Form[this.ListBox1.UniqueID]


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

P: n/a
Thanks, to both of you... Dave

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:pq*************@TK2MSFTNGXA01.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.UniqueID]

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****@aspitalia.com>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <PK*****************************************@comca st.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********************@twister2.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.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!newsfe ed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.PO STE D!not-for-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:117858
| X-Tomcat-NG: microsoft.public.dotnet.framework.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=Request.Params[ListBox1.ClientID]==null?0:Request.Params[ListBox1.C lientID].ToString().Split(',').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

P: n/a
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.public.dotnet.framework.aspnet
| References: <PK*****************************************@comca st.com>
<AI********************@twister2.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********************@comcast.com>
| Lines: 91
| NNTP-Posting-Host: 67.180.218.69
| X-Trace:
sv3-pLUCskW8oRVJlJhN5TQ3G7OE2umQhdZtlRz4BkSwOo6MLIYJqE QC1/Gvq3ntcijMF+BpouA8
svnPHi9!AIczeapVDTMhmkBezfj/yPnxqkQ2bhy09u34cr7Qae35ZBbfhz8palfDS05MZPBIyoVi
q4MqXX90!8TAm
| X-Complaints-To: ab***@comcast.net
| X-DMCA-Complaints-To: dm**@comcast.net
| 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.phx.gbl!TK2MSFTFEED02.phx.gbl!tornad o.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.maxwell.syr.edu!border 1.nntp.dca.giganews.com!lo
cal01.nntp.dca.giganews.com!nntp.comcast.com!news. comcast.com.POSTED!not-for
-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:118151
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks, to both of you... Dave
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:pq*************@TK2MSFTNGXA01.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.UniqueID]
| >
| > 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****@aspitalia.com>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | References: <PK*****************************************@comca st.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********************@twister2.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.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!newsfe
| >
|
ed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.PO STE
| > D!not-for-mail
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:117858
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.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=Request.Params[ListBox1.ClientID]==null?0:Request.Params[ListBox1.C
| > lientID].ToString().Split(',').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 discussion thread is closed

Replies have been disabled for this discussion.