Nick V
Nick V

Reputation: 707

Adjusting Font-Size of ListItem in codebehind

What i'm trying to achieve is to loop through a list and add items to a listbox with different types of styles in an ASP.NET application. so far I've got the following code in my aspx file:

in the header:

<style type="text/css">
        .list .Title
        {
            font-size: x-large;
        }
        .list .Title1
        {
            color:Red;
        } 
        .list .Title2
        {
            color:Black;
        }
        .list .Title3
        {
            color:Green;
        }
         .list .Line
        {
            background-color:Black;
        }

    </style>

Somewhere In the body:

 <asp:ListBox ID="CurrentListBox" runat="server" Width="100%" Height="400" CssClass="list">   
                                </asp:ListBox>

In the code Behind i do this whilst looping through the list items depending on a few factors it goes through one of these:

(I work in VB.NET but an answer in CSharp will do just aswell, i'll translate it)

item.Attributes.Add("class", "Title")

or

item.Attributes.Add("class", "Title1")

or etc. etc. etc.

PROBLEM: It does the colours and it changes it just fine. but the fontsize never changes only the colour gets through.

Maybe some extra information: it loops through this code at pageload.

Upvotes: 0

Views: 2710

Answers (1)

Dev
Dev

Reputation: 6720

Try

 CurrentListBox.Items[0].Attributes.Add("style", "font-size:x-large;");

Thanks

Upvotes: 1

Related Questions