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

Adding Categories In RadListBox

1 Answer 116 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 29 Dec 2010, 12:22 PM
Hi,

I want to add items in a specific category to my RadListBox Control. But I don't know how it would be done. I would like to give an example that how my RadListBox should appears. Fruits and Vegetables are categories and the items appear in each category should appear in a sorted manner in each category. Any help regarding this really appreciated.

Fruits
Apple
Grapes
Orange
Vegetables
Cucumber
Okra
spinach

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Dec 2010, 11:27 AM
Hello Muhammad,

As far as I know, RadListBox does not support "Separator". But the same behaviour can be achieved by using CSS and javascript code. The following CSS is used to set the style for ListItem.

CSS:
.categories
       {
           font-weight: bold;
       }

And in order to disable selection, use the javascript code:
JavaScript:
function OnClientSelectedIndexChanging(sender, args) {
           if ((args.get_item().get_text() == "Fruits") ||(args.get_item().get_text() == "Vegetables"))
               args.set_cancel(true);
           }

And corresponding ASPX will be :
ASPX
<telerik:RadListBox ID="RadListBox1" runat="server" OnClientSelectedIndexChanging="OnClientSelectedIndexChanging">
            <Items>
                <telerik:RadListBoxItem Text="Fruits" CssClass="categories" />
                <telerik:RadListBoxItem Text="Apple" />
                <telerik:RadListBoxItem Text="Vegetables" CssClass="categories" />
                <telerik:RadListBoxItem Text="Cucumber" />
                <telerik:RadListBoxItem Text="Okra" />
            </Items>
</telerik:RadListBox>

Thanks,
Princy.
Tags
ListBox
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or