Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 12, 2009 04:06 AM by susain
Member
6 Points
6 Posts
May 11, 2009 09:55 PM|LINK
Hello Everyone,
I am using C#.Net
I created a checkboxlist with 4 options
example: 1.a, 2.b, 3.c, 4.d
i am collecting the value into variable.
everytime i am able to save 1.a
i want to collect all 4 values if they selected.
i want to collect 3 values if they selected.
all values should go into same variable or column in the database.
Cananyone please help me.
thank you in anticipation,
regards,
john.
All-Star
18687 Points
3124 Posts
MVP
May 12, 2009 12:11 AM|LINK
Yes you can do this. Loop through the CheckBoxList Items collection:
string values = null; for(int i = 0;i < checkboxlist1.Items.Count;i++) { if(checkboxlist1.Items[i].Selected) { values = values + checkboxlist1.Items[i].Value + ","; } }
That will store all the selected values into the variable values.
Star
10892 Points
1567 Posts
May 12, 2009 12:33 AM|LINK
Hi,
Also, you can try this:
Dim Values as string = String.Empty
For each Li as listItem In checkboxlist1.Items
If Li.Selected then Values = Values & ","
Next Li
If Values.EndsWith(",") then Values = Values.Remove(Values.Length-1,1)
''''''''Here, you can save the values to the database....
Any doubt, post your comment.
Contributor
2530 Points
772 Posts
May 12, 2009 04:06 AM|LINK
Hi Segundo,
I tried your code and found that
you made a mistake here If Li.Selected then Values = Values & "," and it should be
Thanks, Farooq
johnkites976...
Member
6 Points
6 Posts
How to collect all values of the checkboxlist into single variable, which is pointed to single co...
May 11, 2009 09:55 PM|LINK
Hello Everyone,
I am using C#.Net
I created a checkboxlist with 4 options
example: 1.a, 2.b, 3.c, 4.d
i am collecting the value into variable.
everytime i am able to save 1.a
i want to collect all 4 values if they selected.
i want to collect 3 values if they selected.
all values should go into same variable or column in the database.
Cananyone please help me.
thank you in anticipation,
regards,
john.
John.
malcolms
All-Star
18687 Points
3124 Posts
MVP
Re: How to collect all values of the checkboxlist into single variable, which is pointed to singl...
May 12, 2009 12:11 AM|LINK
Yes you can do this. Loop through the CheckBoxList Items collection:
string values = null; for(int i = 0;i < checkboxlist1.Items.Count;i++) { if(checkboxlist1.Items[i].Selected) { values = values + checkboxlist1.Items[i].Value + ","; } }Segundo
Star
10892 Points
1567 Posts
Re: How to collect all values of the checkboxlist into single variable, which is pointed to singl...
May 12, 2009 12:33 AM|LINK
Hi,
Also, you can try this:
Dim Values as string = String.Empty
For each Li as listItem In checkboxlist1.Items
If Li.Selected then Values = Values & ","
Next Li
If Values.EndsWith(",") then Values = Values.Remove(Values.Length-1,1)
''''''''Here, you can save the values to the database....
Any doubt, post your comment.
Blog: http://www.neuronasoft.net
susain
Contributor
2530 Points
772 Posts
Re: How to collect all values of the checkboxlist into single variable, which is pointed to singl...
May 12, 2009 04:06 AM|LINK
Hi Segundo,
I tried your code and found that
you made a mistake here If Li.Selected then Values = Values & "," and it should be
If Li.Selected Then Values += Li.Text & "," Then your code is working fine.Thanks,
Farooq