Reputation: 4392
I would like to apply default column-based styles to my GridView
controls using a skin or other function of ASP.NET themes (or really any other automated way).
Currently my GridView skin looks like this:
<asp:GridView runat="server" GridLines="None">
<HeaderStyle CssClass="GridViewRowHeader" />
<FooterStyle CssClass="GridViewRowHeader" />
<RowStyle CssClass="GridViewRowA" />
<AlternatingRowStyle CssClass="GridViewRowB" />
</asp:GridView>
And a typical GridView column definition looks like this:
<Columns>
<asp:BoundField DataField="ExitTimestamp" HeaderText="Exit" SortExpression="ExitTimestamp">
<ItemStyle CssClass="GridViewCell" />
<HeaderStyle CssClass="GridViewHeader" />
</asp:BoundField>
<asp:TemplateField HeaderText="Visitor Name/Agency">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("VisitorName") %>'></asp:Label><br />
<asp:Label ID="Label2" runat="server" Text='<%# Bind("VisitorAgency") %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="GridViewCell" />
<HeaderStyle CssClass="GridViewHeader" />
</asp:TemplateField>
</Columns>
What I would like to get around is having to add the <ItemStyle>
and <HeaderStyle>
elements to every column definition in my GridView
controls. I have tried various ways in the skin file including adding a <Columns>
container and <ItemStyle>
element therein, but nothing seems to work. Is there a way to do this?
Upvotes: 1
Views: 36164
Reputation: 4392
For posterity, here is how I ended up specifically solving the problem using CSS.
I assigned a CSS class to the GridView
in my skin file like so:
<asp:GridView runat="server" CssClass="GridView">
The style selects td
(item) and th
(header) cells within the GridView
and works just as well as applying a plain CSS class directly with ItemStyle
and HeaderStyle
in your Column definitions:
table.GridView tr td, table.GridView tr th
{
/* style attributes here */
}
Upvotes: 2
Reputation: 4686
The advice here may work for you http://forums.asp.net/t/1063057.aspx in short define and add a CssClass to your gridview then use plain old CSS stylesheet to target and decorate the control.
Upvotes: 1