asp:checkboxlist strange error

hehevn88

New Member
Ok, so i'm playing around with the new checkboxlist web <BR>control. I query my database, bind it to the <BR>checkboxlist, and voila it works perfectly. I ran into a <BR>problem though when I went to actually 'collect' the <BR>data. Here's an example:<BR><BR><BR>Sub MyButton_OnClick(sender As Object, e As EventArgs)<BR> Dim myString As String<BR> Dim record As Integer<BR><BR> For record=0 to myCheckBox.Items.Count - 1<BR> If myCheckBox.Items(record).Selected Then<BR> myString = myString & myCheckBox.Items[record].Text<BR> myString = myString & ","<BR> End If <BR> Next record<BR><BR>End Sub<BR><BR><BR><BR>And this refuses to work... I get the strangest error:<BR><BR>The operands to '&' are of types 'String' <BR>and 'System.Web.UI.WebControls.ListItemCollection' , which <BR>are not appropriate for this operator.<BR><BR>And this error points to the line:<BR>myString = myString & myCheckBox.Items[record].Text<BR><BR><BR>This makes no sense to me. myString is declared as a <BR>string! So it's ludicrous that I can't use an ampersand <BR>because it is a string.<BR><BR>I started browsing microsoft's website after I encountered <BR>this and found an example identical to what i'm trying to <BR>do. I tried it out... same thing. Here's their example (which doesn't work):<BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconcheckboxlistwebcontrol.asp<BR><BR>Any ideas on what might be causing this error? I wouldn't think there would be any problem storing this as a string... I'm just confused.<BR><BR>Thanks for any help or guidance you can offer.<BR><BR>-Jer<BR>These are just some ideas, I am not real good with the checkbox yet but here goes...<BR><BR>1. I thought you had to use .Checked and not .Selected with a check box? I am probably wrong on that.<BR><BR>Try this...<BR><BR>myString += myCheckBox.Items[record].Text<BR>myString += ","<BR><BR>...that's usually how I build my strings and it works.Yeah the checked doesn't work in asp.net... only .selected (even for textboxes).<BR><BR>and using <BR><BR>myString += this<BR>myString += that<BR><BR>is equivalent to<BR><BR>myString = myString & this<BR>myString = myString & that<BR><BR>So that didn't seem to work either. It's a strange one... For some reason it's having trouble storing the textbox information into a string, but that doesn't make any sense to me. That's the only way one would use it.<BR><BR>-Jer<BR>Try this from Professional ASP.Net Wrox page 265 and 339<BR>Must Use FindControl when Custom Column is used<BR><BR>Dim mvC As CheckBoxList = CType(e.Item.FindControl("dftWHEREUSE"), CheckBoxList)<BR> Dim mvS As String = ""<BR> Dim objItem As ListItem<BR> For Each objItem In mvC.Items<BR> If objItem.Selected Then mvS = mvS & objItem.Value<BR> Next<BR> msglabel.Text = mvS<BR>What happens if you just do a ...<BR><BR>Dim myString<BR><BR>and not a Dim myString As String...any better luck with that?
 
Back
Top