GridView用CSS设定样式
来源:互联网 发布:迁移阿里云rds到aws 编辑:程序博客网 时间:2024/05/21 14:46
GridView是很便利的数据控件,在MIS中的应用很广泛,其样式编写很简单,但是每次新增都要重新编写,工作很是烦琐,而且由于其本身的特性,样式并不好编写,最好的办法就是在单双行、Header、Pager、Footer等栏目引用单独的样式,如下:
<asp:GridView ID="grvAdUserInfo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" AllowPaging="True" PageSize="12" HorizontalAlign="Center" CssClass="GridView" OnPageIndexChanging="grvAdUserInfo_PageIndexChanging"> <Columns> <asp:BoundField DataField="EMPLOYEEID" HeaderText="工號" /> <asp:BoundField DataField="TRUENAME" HeaderText="姓名" /> </Columns> <EmptyDataTemplate> <span style="text-align: center; font-size: larger; font-weight: bolder; color: Blue;">抱歉,暫時沒有數據!</span> </EmptyDataTemplate> <AlternatingRowStyle CssClass="GridView_Row_Alter" /> <PagerStyle CssClass="GridView_Pager" /> <HeaderStyle CssClass="GridView_Header" /> <RowStyle CssClass="GridView_Row" /> <SelectedRowStyle CssClass="GridView_Row_Select" /> </asp:GridView>各样式如下:
/*****************GridView 樣式*******************//************GridView頁碼樣式************/.GridView_Pager { background-color: #507CD1; font-weight: bold; color: white; height: 35px; font-size: 14px;} .GridView_Pager td a:hover { width: 20px; color: white; padding-left: 4px; padding-right: 4px; } .GridView_Pager td a:active { width: 20px; color: white; padding-left: 4px; padding-right: 4px; } .GridView_Pager td a:link { width: 20px; color: white; padding-left: 4px; padding-right: 4px; } .GridView_Pager td a:visited { width: 20px; color: white; padding-left: 4px; padding-right: 4px; } .GridView_Pager td span { font-weight: bold; font-size: 15px; width: 20px; color: red; padding-left: 4px; padding-right: 4px; }/******GridView標題欄樣式********/.GridView_Header { color: white; background-color: #507CD1; height: 35px; font-size: 14px; font-weight: bold;}/**********GridView主樣式*************/.GridView_Main { border-color: white; width: 100%;}/************GridView RowStyle************/.GridView_Row { background-color: #EFF3FB; height: 25px; text-align: center; color: #333333;}.GridView_Row_Alter { background-color: white; height: 25px; text-align: center; color: #333333;}.GridView_Row_Select { background-color: #D1DDF1; color: #333333; font-weight: bold;}
这是我现在使用的方法,对样式的设置只需引用,还是很方便的。但是我是一个不断追寻轻松的懒人,能不能只在GridView开头引用样式就一劳永逸呢?由于GridView实质上在HTML的表现为一个table,所以其实可以通过写table样式来对其进行设置,如下:
<asp:GridView ID="grvAdUserInfo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" AllowPaging="True" PageSize="12" HorizontalAlign="Center" CssClass="GridView" OnPageIndexChanging="grvAdUserInfo_PageIndexChanging"> <Columns> <asp:BoundField DataField="EMPLOYEEID" HeaderText="工號" /> <asp:BoundField DataField="TRUENAME" HeaderText="姓名" /> </Columns> <EmptyDataTemplate> <span style="text-align: center; font-size: larger; font-weight: bolder; color: Blue;">抱歉,暫時沒有數據!</span> </EmptyDataTemplate> </asp:GridView>样式文件如下:
/*****以下GridView的樣式目前還未完成,處於測試階段*********/.GridView { width: 100%;} .GridView th { color: white; background-color: #507CD1; height: 35px; font-size: 14px; font-weight: bold; } .GridView tr { background-color: #EFF3FB; height: 25px; text-align: center; } .GridView tr td { text-align: center; } .GridView td table { background-color: #507CD1; text-align: center; } .GridView td table td { text-align: center; } .GridView td table td A:hover { width: 20px; color: black; padding-left: 4px; padding-right: 4px; } .GridView td table td A:active { width: 20px; color: black; padding-left: 4px; padding-right: 4px; } .GridView td table td A:link { width: 20px; color: black; padding-left: 4px; padding-right: 4px; } .GridView td table td A:visited { width: 20px; color: black; padding-left: 4px; padding-right: 4px; } .GridView td table td span { font-weight: bold; font-size: 15px; width: 20px; color: red; padding-left: 4px; padding-right: 4px; }这样设置看起来好像没有问题,但是并不能达到一些要求,比如单双行不同样式,页码Pager自定义样式等,由于在此之前对样式没有过了解,所以有待后期完善。而且还有一个问题,就是页码的居中,需要在GridView的属性中加上如下一句:
HorizontalAlign="Center"
CSS还是很强大的,仔细研究说不定就能完善这个样式了。
经过多次测试,我已经可以确定了以上样式是可行的,不过IE8不支持CSS3,所以我一直以来都以为样式有问题。。
论来自IE8的恶意。。
0 0
- GridView用CSS设定样式
- table css样式设定中的宽度设定
- css超链接的样式设定
- GridView CSS样式
- GridView与css样式
- GridView CSS样式
- GridView CSS的样式表
- 网页CSS样式行间距设定
- 格式化gridview:设定样式和连接数据库字段【转】
- 关于如何设定css样式使得文本溢出部分用省略号代替
- GridView CSS的完整样式表
- .net中用css控制GridView样式
- GridView CSS的完整样式表
- GridView CSS的样式表(固定表头)
- .net中用css控制GridView样式
- GridView CSS的完整样式表
- .net中 css 控制 GridView 样式
- GridView CSS的完整样式表
- LuaTinker
- ERROR:can't locate file for xxx
- spring mvc配置(xml配置详解)
- C++/C笔试面试题目大大的集合
- php中查询mysql 如何在WHERE meta_id IN 中用数组
- GridView用CSS设定样式
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现
- Cisco 中line密码的几点理解
- Execution failed for task ': :dexDebug'
- LeetCode Search for a Range
- android ant 多渠道打包
- 【Extjs】上传文件
- 进程、线程同步互斥学习 —— 信号量
- require.js的用法