Cannot get the last item count

2 posts, 0 answers
  1. Michelle Tan
    Michelle Tan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    Hi, I am new to telerik. I having problem with checking the last item in the listbox. Basicly it will loop alll the item in the listbox and combine it become a string, When listbox item reach end it will replace with "." instead of "',". Please help.Thanks
     
    Dim sb As New StringBuilder    
     
    For Each item As RadListBoxItem In radCustomer.Items
           
      If  radNotMemberOf.Items.Count.ToString.Length - 1 Then
     hdnCustomerList.Value = hdnCustomerList.Value & sb.Append(item.Value.Replace(",", ".")).ToString
    Else
      hdnCustomerList.Value = sb.Append(item.Value & ",").ToString()
     
    End If
          Next
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2012 Link to this post

    Hi,

    Try the following code to achieve your scenario.

    VB:
    If True Then
        Dim sb As New System.Text.StringBuilder()
     
        For Each item As RadListBoxItem In radCustomer.Items
            If item.Index = (AllAreas.Items.Count - 1) Then
                hdnCustomerList.Value = hdnCustomerList.Value + sb.Append(item.Value.Replace(",", ".")).ToString
            Else
                hdnCustomerList.Value = sb.Append(item.Value + ",").ToString()
            End If
        Next
    End If

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top