使用普通CSS为asp:GridView定义全局站点风格(不使用VS皮肤)(Define global site style for asp:GridView with plain CSS (with

编程入门 行业动态 更新时间:2024-10-26 23:26:08
使用普通CSS为asp:GridView定义全局站点风格(不使用VS皮肤)(Define global site style for asp:GridView with plain CSS (without using VS Skins))

我正在处理一个相当大的aspx Web项目,并广泛使用了asp:GridViews

我想用CSS在一个地方定义所有GridView默认情况下的外观。

据我了解,这样做的一种方式是通过Visual Studio中的“皮肤”......但我记得回顾了一段时间的研究,发现许多人鄙视皮肤,并始终在asp.net中使用纯CSS项目(尽管我不能完全记得他们的糟糕之处)。

所以我的问题是:1)是否有可能使用普通CSS做这个全局默认的asp:GridView样式2)使用VS Skins有什么优势,或者只是普通的CSS,就像使用皮肤一样强大且易于维护?

更新:我也想提一下,GridView有许多独特的样式,比如SelectedRowStyle-BackColor; 这对我原来的问题有什么影响吗? 如果有人可以发布或链接到任何这样的例子,这将是非常有益的。

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

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

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).

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

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.

最满意答案

定义一个样式表并在某处设置这些样式:

/** * 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的优势:

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

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; }

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">

更多推荐

CSS,asp,GridView,使用,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-07-31 02:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   定义   皮肤   风格   站点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!