Separators for Databound Items

4 posts, 1 answers
  1. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 08 Nov 2012 Link to this post

    Hello,

    I want to bind a RadListBox to a list of a simple class:

    Public Class ExampleInfo
        Property ID as integer
        Property Text as String
        Property Category as string
    End Class

    I would like to add separators to the list by category. Physically, that's easy - I just made the separator items disabled and applied a special css class. But, I am having trouble positioning them. Here's been my current approach:
    Private _curCategory as string = ""
    Private Sub mainList_ItemDataBound(sender As Object, e As Telerik.Web.UI.RadListBoxItemEventArgs)
            Dim dataRow As ExampleInfo = DirectCast(e.Item.DataItem, ExampleInfo)
            Dim LocalCategory as string  = dataRow.Category
            If _curCateogry <> LocalCategory Then
                Dim sepItem As New RadListBoxItem(LocalCategory, 0)
                sepItem.Enabled = False
                sepItem.CssClass = "listSeparator"
                sepItem.Attributes.Add("isSeparator", "True")
                mainList.Items.Add(sepItem)
            End If
            e.Item.Attributes.Add("isSeparator", "False")
            e.Item.ToolTip = dataRow.Description
    End Sub

    This adds the items just fine but, of course, they are added below the first item in the new category. I tried reordering them in the DataBound event for the list but I haven't been able to get that to work.

    Can anybody help - how can I add separator items?

    Thanks,

    Mike
  2. Answer
    Kate
    Admin
    Kate avatar
    1898 posts

    Posted 13 Nov 2012 Link to this post

    Hello Mike,

    Try inserting the items instead of adding them  - mainList.Items.Insert(e.Item.Index,sepItem)  instead of the mainList.Items.Add(sepItem).

    All the best,
    Kate
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 14 Nov 2012 Link to this post

    Hello,

    That did it - thanks!

    The only trouble is that adding the items messes up the indexes. So, transferring items at the end causes an error because it thinks their index doesn't exist. Also, when I transfer things back, I have to do a full rebind to get them to position correctly. I guess I'll just have to figure out a different way to do what I want until separators and grouping are fully supported.

    Thanks,

    Mike
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 19 Nov 2012 Link to this post

    Hello Mike,

    After further testing the scenario with the custom separators I could not get any errors - transferring and reordering items works as expected from my side. Please check the attached page and let me know how it goes from your side.

    Greetings,
    Kate
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top