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

How to change the text style of a single Item

4 Answers 242 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Cory Hudson
Top achievements
Rank 2
Cory Hudson asked on 31 Aug 2009, 07:58 PM
Hello,

I am trying to change the color of a single data bound item within a RadListBox control, but I am not exactly sure when/where I should do this.

I tried something along these lines, but I am not getting the text Color to change.
protected void listBoxLocations_ItemDataBound(object sender, RadListBoxItemEventArgs e) 
        { 
            if (attribute) 
                e.Item.ForeColor = System.Drawing.Color.Gray; 
        } 

Does anyone know what I should do differently? (pre-render, different item attribute etc?)

4 Answers, 1 is accepted

Sort by
0
Cory Hudson
Top achievements
Rank 2
answered on 31 Aug 2009, 08:55 PM
So, I have played with this a bit more and I can get some things to work in ItemDataBound or Pre-Render.  I also added a css class to the item
protected void listBoxLocations_ItemDataBound(object sender, RadListBoxItemEventArgs e) 
        { 
            if (attribute) 
                e.Item.CssClass = "css1";     
        } 
.css1 
    background-color: #E5E5E5; 
    text-align:right; 
    color:Red; 

Now, I get the all the elements of the css class, except I do not get the red text color.  Given that I know next to nothing about css, is my issue a css thing? Any other thoughts?

Thanks,

Cory
0
Veselin Vasilev
Telerik team
answered on 01 Sep 2009, 03:21 PM
Hi Cory Hudson,

Actually the red color is applied when I tested it.

Here is my simple test:

<telerik:RadComboBox ID="RadComboBox1" runat="server"
    <Items> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1"  
            Value="RadComboBoxItem1" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" CssClass="css1"  
            Value="RadComboBoxItem2" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3"  
            Value="RadComboBoxItem3" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem4"  
            Value="RadComboBoxItem4" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem5"  
            Value="RadComboBoxItem5" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem6"  
            Value="RadComboBoxItem6" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem7"  
            Value="RadComboBoxItem7" /> 
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem8"  
            Value="RadComboBoxItem8" /> 
    </Items> 
</telerik:RadComboBox> 

    <style type="text/css"
.css1  
{  
    background-color: Aqua;  
    text-align:rightright;  
    color:Red;  
}  
        </style> 


Best wishes,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Cory Hudson
Top achievements
Rank 2
answered on 01 Sep 2009, 05:35 PM
Thanks for the reply Veselin, but there are 2 things different here.

1.  I am using a data bound RadListBoxControl.
2.  Programmatic (conditional) assignment of the css class to a single item within the List Box.

When I do this to the list box, I can get a variety of css styles to apply, but never the text color...

Any thoughts?
0
Cory Hudson
Top achievements
Rank 2
answered on 02 Sep 2009, 09:29 PM
I found a solution to this by creating a custom skin and removing the default reference to color: #000;
Now I can set the forecolor of ListBox items to whatever i want via code.
Tags
ListBox
Asked by
Cory Hudson
Top achievements
Rank 2
Answers by
Cory Hudson
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or