Saturday, March 24, 2012

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, DaveDave H <DaveH@.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
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" <andrew@.aspitalia.com>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <PKWdnZ2dnZ314u2KnZ2dnZOtYN-dnZ2dRVn-yp2dnZ0@.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: <AIDLe.16268$F23.191718@.twister2.libero.it>
| Date: Sun, 14 Aug 2005 08:58:08 GMT
| NNTP-Posting-Host: 151.47.29.112
| X-Complaints-To: abuse@.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!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 <DaveH@.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
|
|
|
|
Steven Cheng[MSFT] <stcheng@.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
Thanks, to both of you... Dave
"Steven Cheng[MSFT]" <stcheng@.online.microsoft.com> wrote in message
news:pqOmJEUoFHA.940@.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" <andrew@.aspitalia.com>
> | Newsgroups: microsoft.public.dotnet.framework.aspnet
> | References: <PKWdnZ2dnZ314u2KnZ2dnZOtYN-dnZ2dRVn-yp2dnZ0@.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: <AIDLe.16268$F23.191718@.twister2.libero.it>
> | Date: Sun, 14 Aug 2005 08:58:08 GMT
> | NNTP-Posting-Host: 151.47.29.112
> | X-Complaints-To: abuse@.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!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 <DaveH@.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
> |
> |
> |
> |
>
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" <DaveH@.noemail.nospam>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| References: <PKWdnZ2dnZ314u2KnZ2dnZOtYN-dnZ2dRVn-yp2dnZ0@.comcast.com>
<AIDLe.16268$F23.191718@.twister2.libero.it>
<pqOmJEUoFHA.940@.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: <C9OdnWMTWNV_zpzeRVn-jQ@.comcast.com>
| Lines: 91
| NNTP-Posting-Host: 67.180.218.69
| X-Trace:
sv3- pLUCskW8oRVJlJhN5TQ3G7OE2umQhdZtlRz4BkSw
Oo6MLIYJqEQC1/Gvq3ntcijMF+BpouA8
svnPHi9!AIczeapVDTMhmkBezfj/ yPnxqkQ2bhy09u34cr7Qae35ZBbfhz8palfDS05M
ZPBIyoVi
q4MqXX90!8TAm
| X-Complaints-To: abuse@.comcast.net
| X-DMCA-Complaints-To: dmca@.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!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
|
| "Steven Cheng[MSFT]" <stcheng@.online.microsoft.com> wrote in message
| news:pqOmJEUoFHA.940@.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" <andrew@.aspitalia.com>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | References: <PKWdnZ2dnZ314u2KnZ2dnZOtYN-dnZ2dRVn-yp2dnZ0@.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: <AIDLe.16268$F23.191718@.twister2.libero.it>
| > | Date: Sun, 14 Aug 2005 08:58:08 GMT
| > | NNTP-Posting-Host: 151.47.29.112
| > | X-Complaints-To: abuse@.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!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 <DaveH@.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
| > |
| > |
| > |
| > |
| >
|
|
|

0 comments:

Post a Comment