Define a global site style for asp: GridView with simple CSS (without using VS Skins)

I am working on a fairly large aspx web project with extensive use of asp: GridViews

I would like to use CSS to define in one place what all gridviews will look like by default.

As far as I understand, one way to do this is through the “skins” in Visual Studio .... but I remember doing a little research and found a lot of people who despise the skins and always used simple CSS in asp.net (although I I can’t completely remember what was so bad about them).

So my questions are: 1) Can I make this global default asp: GridView style using simple CSS 2) Is there any advantage to using VS Skins in general, or is simple CSS just as powerful and easy to maintain as using skins?

UPDATE: I also wanted to mention that there are many styles unique to GridView, such as SelectedRowStyle-BackColor; Does this affect my initial question? If someone could post or link to any examples of this, that would be very helpful.

+4
source share
3 answers

Define a stylesheet and set these styles somewhere:

/** * GRIDVIEW STYLES **/ .gridview { font-family:"arial"; background-color:#FFFFFF; width: 100%; font-size: small; } .gridview th { background: #7AC142; padding: 5px; font-size:small; } .gridview th a{ color: #003300; text-decoration: none; } .gridview th a:hover{ color: #003300; text-decoration: underline; } .gridview td { background: #D9EDC9; color: #333333; font: small "arial"; padding: 4px; } .gridview tr.even td { background: #FFFFFF; } .gridview td a{ color: #003300; font: bold small "arial"; padding: 2px; text-decoration: none; } .gridview td a:hover { color: red; font-weight: bold; text-decoration:underline; } 

Then your gridview needs to be configured to use them using CssClass and AlternatingRowStyle-CssClass:

 <asp:GridView ID="GridView1" runat="server" CssClass="gridview" AlternatingRowStyle-CssClass="even"> 
+15
source

You might want to use friendly css adapters, which you will get a little cleaner html from gridview. Just look at the html output and usually create css. If you need to find something specific in gridview, you can use the global skin to assign the css class so you can style it too.

+1
source

Gridview will be displayed as an HTML table. You can assign it a class and style, like any other table. I don't know anything about VS Skins, but I designed many gridviews this way.

0
source

All Articles