Append Collection

The attached spipped gets items checked in my RadListBok and appends or refreshes my label.

However...it is DOUBLE appending the items...and without the  seperating comma
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        getFIPS(RadListBox1, itemsFips, ckAppend)
    End Sub

Private Shared Sub getFIPS(ByVal listBox As RadListBox, ByVal label As Label, ByVal ckAppend As CheckBox)
        Dim sb As New StringBuilder()
        Dim collection As IList(Of RadListBoxItem) = listBox.CheckedItems
        For Each item As RadListBoxItem In collection
            sb.Append(item.Value & ",")
        Next
        If ckAppend.Checked = True Then
            label.Text = label.Text & sb.ToString().Substring(0, sb.ToString().Length - 1)
        Else
            label.Text = sb.ToString().Substring(0, sb.ToString().Length - 1)
        End If
    End Sub

Open in new window

lrbristerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
13598Connect With a Mentor Commented:
Try this:
Private Shared Sub getFIPS(ByVal listBox As RadListBox, ByVal label As Label, ByVal ckAppend As CheckBox)
        Dim sb As New StringBuilder()  = ""
        Dim collection As IList(Of RadListBoxItem) = listBox.CheckedItems
        For Each item As RadListBoxItem In collection
if sb.tostring.trim = "" then
  sb.Append(item.Value )
else
  sb.Append("," & item.Value  )
end if
         
        Next
        If ckAppend.Checked = True Then
            label.Text = label.Text & sb.ToString.trim
        Else
            label.Text = sb.ToString.trim
        End If
    End Sub
0
 
nomooseCommented:
Are you sure you're clearing out the target control's items before you append?  From your code it looks like that label should have the checked items put into it when you click the button, but if you don't clear out the label it'll keep adding them.

If this isn't the case is the label being touched anywhere else in the code?
0
 
lrbristerAuthor Commented:
nomoose:
If I take out the logic for the checkbox and simply have the code below it over writes every time.
blah..blah..blah..
             label.Text = sb.ToString().Substring(0, sb.ToString().Length - 1)
    End Sub

I want it to do that IF the checkbox is NOT checked, but append the new information if it is.

The actual button that calls the Button1_Click is:
<asp:Button ID="Button1" runat="server" CssClass="ButtonSmall" OnClick="Button1_Click"  Text="Get Selected Items!" />

0
 
nomooseCommented:
I'm not sure if this will fix the problem entirely, but try the following things in the order stated because one will resolve the others...

1) In visual studio next to the play (a green arrow) button in the debug toolbar it has a dropdown. Make sure that dropdown is set to "Debug"  If it's set to release the debug files for the site won't be created or updated.

2) In your web.config file there is a line in the <system.web>  tag that says "compilation debug".  Make sure that looks like this:

<compilation debug="true">

3) Another thing you can try is right clicking on the solution in visual studio and click "property pages."  In that window go to "Start Options" and under "Debuggers" make sure "ASP.NET" is checked off.

If those don't work I can dig around and try to think of more creative ways to get the debugger to do what it's supposed to.
0
 
nomooseCommented:
Disregard the above post, EE and Google Chrome do not play well together.  For some reason it was posting my responses to all the other posts I had visited.
0
All Courses

From novice to tech pro — start learning today.