Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 12, 2009 04:06 AM by susain
May 11, 2009 09:55 PM|LINK
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,
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++)
values = values + checkboxlist1.Items[i].Value + ",";
That will store all the selected values into the variable values.
May 12, 2009 12:33 AM|LINK
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 & ","
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.
May 12, 2009 04:06 AM|LINK
I tried your code and found that
you made a mistake here If Li.Selected then Values = Values & "," and it should be