listbox - mulitple selection detection

  • Thread starter Thread starter Dave H
  • Start date Start date
D

Dave H

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
 
Dave H said:
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
 
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" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <[email protected]>
| 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: <[email protected]>
| Date: Sun, 14 Aug 2005 08:58:08 GMT
| NNTP-Posting-Host: 151.47.29.112
| X-Complaints-To: (e-mail address removed)
| 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!newsfeed00.sul.t-online.de!newsfe
ed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.POSTE
D!not-for-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:117858
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Dave H <[email protected]> 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
|
|
|
|
 
Thanks, to both of you... Dave

Steven Cheng said:
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" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <[email protected]>
| 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: <[email protected]>
| Date: Sun, 14 Aug 2005 08:58:08 GMT
| NNTP-Posting-Host: 151.47.29.112
| X-Complaints-To: (e-mail address removed)
| 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!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.POSTE
D!not-for-mail
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:117858
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Dave H <[email protected]> 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
|
|
|
|
 
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" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <[email protected]>
<[email protected]>
<[email protected]>
| 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: <[email protected]>
| Lines: 91
| NNTP-Posting-Host: 67.180.218.69
| X-Trace:
sv3-pLUCskW8oRVJlJhN5TQ3G7OE2umQhdZtlRz4BkSwOo6MLIYJqEQC1/Gvq3ntcijMF+BpouA8
svnPHi9!AIczeapVDTMhmkBezfj/yPnxqkQ2bhy09u34cr7Qae35ZBbfhz8palfDS05MZPBIyoVi
q4MqXX90!8TAm
| X-Complaints-To: (e-mail address removed)
| X-DMCA-Complaints-To: (e-mail address removed)
| 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!tornado.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.maxwell.syr.edu!border1.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
|
| | > 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" <[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | References: <[email protected]>
| > | 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: <[email protected]>
| > | Date: Sun, 14 Aug 2005 08:58:08 GMT
| > | NNTP-Posting-Host: 151.47.29.112
| > | X-Complaints-To: (e-mail address removed)
| > | 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!newsfeed00.sul.t-online.de!newsfe
| >
|
ed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.POSTE
| > D!not-for-mail
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:117858
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Dave H <[email protected]> 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
| > |
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top