IceDawg
IceDawg

Reputation: 327

How to set font size, family and colour of listview in ASP.NET (C#)

So I have the following ListView1

[asp.net]

 <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
            onprerender="ListView1_PreRender" 
            onselectedindexchanged="ListView1_SelectedIndexChanged">

To which I have tried to set the following properties through CSS

[css]

#ListView1
{
    color: White;
    font-family: Calibri;
}

But that did not work for some reason.

Upvotes: 0

Views: 1937

Answers (3)

Amitd
Amitd

Reputation: 4859

you can try the CssClass property

.ListView1
{
    color: White;
    font-family: Calibri;
}

and then use it as

<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
            onprerender="ListView1_PreRender"  CssClass= "ListView1"
            onselectedindexchanged="ListView1_SelectedIndexChanged">

You can style it more better if you use the ItemTemplate / LayoutTemplate as shown here

Upvotes: 1

scartag
scartag

Reputation: 17680

You could set the ClientIdMode to static to ensure that the ID of the server control doesn't change when it is rendered as html even if it is in a container or a master page.

 <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
            onprerender="ListView1_PreRender" 
            onselectedindexchanged="ListView1_SelectedIndexChanged" ClientIdMode="Static">

Upvotes: 1

Stephen Fischer
Stephen Fischer

Reputation: 2546

runat='server' will change element IDs often times, appending the name of the class of the page. You can do two things to fix the issue:

1) Change the name of the ID selector in CSS to match what the ID is altered to be (which you figure out by doing a view source on the rendered page).

2) Apply a class to the element instead of using the ID.

The second one is probably better, as you can reuse that class on other pages without changing any CSS, and it's a bit more straightforward.

Upvotes: 0

Related Questions