Bit of a basic question, but I'm a bit rusty with CSS, but I've been requested to use CSS rather than the 'gridview style' tags (as I'll show below).
Basically, I use the following style on my GridView:
<RowStyle BackColor="#ededed" ForeColor="#333" HorizontalAlign="Center" />
<FooterStyle BackColor="#465F7F" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#465F7F" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#465F7F" Font-Bold="false" ForeColor="#ffffff开发者_JAVA技巧" />
<HeaderStyle BackColor="#465F7F" Font-Bold="false" ForeColor="White" HorizontalAlign="Center" />
<EditRowStyle BackColor="#B7B7B7" />
<AlternatingRowStyle BackColor="#e2e6e8" ForeColor="#333333" />
Could I convert this to CSS? So I can just set my GridView CssClass and it'd apply all these styles. Right now that code is replicated on every grid, so changing it is a chore!
Just use CssClass
property of the grid and put everything to that css class and you're done!
For example instead of this:
<RowStyle BackColor="#ededed" ForeColor="#333" HorizontalAlign="Center" />
you would use same markup for all your common style grids:
<RowStyle CssClass="gridViewRow" />
And the css class then would look like this:
.gridViewRow
{
background-color:#ededed;
color:#333;
text-align:center;
}
By replacing the corresponding styles below you will get the same effect.
Also you should consider using JQuery Theme Roller's styles instead to easily make the grid look really nice. http://jqueryui.com/themeroller/
.RowStyle
{
background-color: #ededed;
color:#333;
text-align:center;
}
.FooterStyle
{
background-color:#465F7F; font-weight: bold; color:White;
}
.PagerStyle {background-color:#465F7F; color:White; text-align:center; }
.SelectedRowStyle { background-color:#465F7F; font-weight: normal; color:#ffffff }
.HeaderStyle {background-color:#465F7F; font-weight: normal; color:White; text-align:center; }
.EditRowStyle {background-color:#B7B7B7; }
.AlternatingRowStyle {background-color:#e2e6e8; color:#333333 }
Apply your base style to the GridView and use the power of CSS
<asp:GridView id="gvTestGrid" runat="server" cssclass="gridview-common" >
<HeaderStyle cssClass="gridview-header" />
...
</asp:GridView>
CSS
.gridview-common {
/* table styles */
}
.gridview-common th.gridview-header, .gridview-common th.gridview-header:hover {
/* Header styles */
}
.gridview-common tbody tr {
/* Row styles */
}
.gridview-common tbody tr:hover {
/* Row Hover styles */
}
精彩评论