How to change the text style of a single Item

5 posts, 0 answers
  1. Cory Hudson
    Cory Hudson avatar
    12 posts
    Member since:
    Nov 2008

    Posted 31 Aug 2009 Link to this post

    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?)
  2. Cory Hudson
    Cory Hudson avatar
    12 posts
    Member since:
    Nov 2008

    Posted 31 Aug 2009 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 01 Sep 2009 Link to this post

    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.
  5. Cory Hudson
    Cory Hudson avatar
    12 posts
    Member since:
    Nov 2008

    Posted 01 Sep 2009 Link to this post

    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?
  6. Cory Hudson
    Cory Hudson avatar
    12 posts
    Member since:
    Nov 2008

    Posted 02 Sep 2009 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017