本文介绍了定义ASP全球网站风格:GridView控件用普通的CSS(不使用VS皮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作具有广泛的使用ASP的一个相当大的aspx web项目:GridView的

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

我想使用CSS在一个地方定义所有的GridView的会怎么看,在默认情况下。

I'd like to use CSS to define in one place how all gridviews will look, by default.

据我了解,这样做的一个方法是通过在Visual Studio中的皮肤....但我记得做了一些研究了一段时间后,发现很多人鄙视的皮肤,总是使用只是普通的CSS asp.net项目(虽然我不能完全记得什么是坏对他们)。

As far as I understand, one way of doing this is via "Skins" in Visual Studio....but I recall doing a bit of research a while back and found many people despised skins and always used just plain CSS in asp.net projects (although I can't entirely remember what was so bad about them).

所以我的问题是:
1)是否有可能做到这一点全局默认的asp:使用纯CSS样式的GridView
2)有任何优势,使用VS皮肤所有,或只是普通的CSS一样强大和易于维护与使用皮肤?

So my questions are:1) Is it possible to do this global default asp:GridView styling using plain CSS2) Is there any advantage to using VS Skins at all, or is just plain CSS just as powerful and easily maintained as using skins?

更新:我也意味着一提的是有独特的GridView控件,如SelectedRowStyle,背景色款式很多;这确实对我原来的问题有何影响?如果有人可以张贴或链接到任何的例子将是非常有益的。

UPDATE: I also meant to mention that there are many styles unique to the GridView, such as SelectedRowStyle-BackColor; does this have any impact on my original question? If someone could post or link to any examples of this it would be extremely helpful.

推荐答案

定义样式表,并在哪儿设置这些样式:

Define a stylesheet and set these styles up 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;     
}

您的GridView则需要进行设置,以充分利用这些使用的CssClass和AlternatingRowStyle-的CssClass的:

Your gridview then needs to be setup to take advantage of these using CssClass and AlternatingRowStyle-CssClass:

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

这篇关于定义ASP全球网站风格:GridView控件用普通的CSS(不使用VS皮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:23