786 snippets from 1631 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(142)
JavaScript
(125)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
File
(29)
CSharp
(28)
HTML
(27)
mysql
(27)
C
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Detect Adblock
Concatenar campos...
fopen
Unique random key
get number of cha...
Find a File
Find a Directory
List Directory
File uploading in...
Get Values from C...
Venture Capital Jobs
New Members
mcheung63
cicero
mycodeofshailendra
nostromo
KennethCC
me
jamesmcm
Can
Kelmi
ysg
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Get Selected Values From a CheckBoxList in C#
/
Comments
Get Selected Values From a CheckBoxList in C#
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
New Comment
Not sure but...
Thu. Sep. 21st, 2006 8:04 AM
Pio
I know in Windows Forms the CheckedListBox has a property named CheckedItems. This is alot easier to use, since it's being given to us already.
Allen / Pio
email: intolerance@gmail.com
// Get Values from CheckBoxList, mod by Pio.
String
values =
""
;
for
(
int
i=
0
; i< cbl.
CheckedItems
.
Count
; i++
)
{
values += cbl.
CheckedItems
.
Item
[
i
]
.
Value
+
","
;
}
values = values.
TrimEnd
(
','
)
;
That should do it.
Reply
Thanks.. works great
Mon. Dec. 18th, 2006 11:45 PM
mixilplix
Works great.. thanks a lot for posting it.
Reply
Another way
Thu. Nov. 15th, 2007 4:54 AM
cykophysh
An Alternative way it to iterate through the items collection
foreach
(
ListItem li in CheckBoxList.
Items
)
{
if
(
li.
Selected
)
//do something
}
[tongue]
Reply
good one
Tue. Oct. 14th, 2008 3:31 AM
khaled88
thanks that was helpful
Reply
New Comment
Allen / Pio
email: intolerance@gmail.com
// Get Values from CheckBoxList, mod by Pio.
String values = "";
for (int i=0; i< cbl.CheckedItems.Count; i++)
{
values += cbl.CheckedItems.Item[i].Value + ",";
}
values = values.TrimEnd(',');
foreach(ListItem li in CheckBoxList.Items)
{
if(li.Selected) //do something
}