This is a migrated thread and some comments may be shown as answers.

Separators for Databound Items

3 Answers 48 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 08 Nov 2012, 05:40 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Kate
Telerik team
answered on 13 Nov 2012, 02:29 PM
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.
0
Mike
Top achievements
Rank 1
answered on 14 Nov 2012, 04:59 PM
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
0
Kate
Telerik team
answered on 19 Nov 2012, 02:29 PM
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.
Tags
ListBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Kate
Telerik team
Mike
Top achievements
Rank 1
Share this question
or