在做项目时候需要修改webdiyer:AspNetPager分页控件的样式,查找了很多资料。总结如下。
1.引入样式表。
将想要使用的样式表加入到本页面<styletype="text/css"></style>标记中,或者新建一个css文件如:AspNetPager.css,将样式粘贴进去,并在页面添加<link href="AspNetPager.css" rel="stylesheet" type="text/css" />进行引用。
2.添加AspNetPager控件属性:CssClass="paginator" CurrentPageButtonClass="cpb"
举例说明:
首先,新建AspNetPager.css文件,将如下内容粘贴到里面,保存在和页面同级的目录下吧。
/*拍拍网风格*/这个不是很符合项目的要求
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
/*淘宝风格*/
.paginator { font: 12px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}这句默认的样式,所有的页码都得服从
.paginator a {border:solid 1px #ccc;color:#0063dc;cursor:pointer;text-decoration:none;}//webdiyer:AspNetPager所有的页码应该都是用a写的。所以这句也是没有点击页码时候显示的样式,这可以自己加背景啊啥的。加背景图片也很方便
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}//点击完成以后显示的样子
.paginator .cpb {border:1px solid #F50;font-weight:700;color:#F50;background-color:#ffeee5;}//这句是选中页码的样式
.paginator a:hover {border:solid 1px #F50;color:#f60;text-decoration:none;}//这句是鼠标放上去的样式
.paginator a,.paginator a:visited,.paginator .cpb,.paginator a:hover //这句是公共样式。所有的都得先服从这里的样式
{float:left;height:16px;line-height:16px;min-width:10px;_width:10px;margin-right:5px;text-align:center;
white-space:nowrap;font-size:12px;font-family:Arial,SimSun;padding:0 3px;}
/*项目风格*/
.rig_fenye{ height:36px; margin:0 auto; margin-left:150px;}
.rig_fenye li{ width:37px; height:36px; float:left; background:url(../index_img/shuzi.gif); line-height:32px; text-align:center;}
.rig_fenye li:hover{ width:37px; height:36px; float:left; background:url(../index_img/dang.gif); line-height:31px; text-align:center;}
.rig_fenye li a{ color:#3c383b; font-size:14px; font-family:Arial; font-weight:bolder; text-decoration:none; display:block; margin-right:1px;}
.rig_fenye li a:hover{ color:#752900; font-size:14px; font-family:Arial; font-weight:bolder;}
.paginator a { float:left; height:36px; line-height:32px; padding:0px 14px; background:url(../images/shuzi.gif) no-repeat center center; text-align:center;text-decoration:none; color:#333;
font-size:14px; font-family:Arial; font-weight:bolder; }
.paginator .cpb { float:left; height:36px; padding:0px 14px; line-height:32px; background:url(../images/dang.gif) no-repeat center center; text-align:center;text-decoration:none; color:#752900;
font-size:14px; font-family:Arial; font-weight:bolder; }
.paginator a:hover { float:left; height:36px; padding:0px 14px; line-height:32px; background:url(../images/dang.gif) no-repeat center center; text-align:center;text-decoration:none; color:#752900;
font-size:14px; font-family:Arial; font-weight:bolder;}
.npb{ float:left;}
接着,在页面内添加<link href="AspNetPager.css" rel="stylesheet" type="text/css" />标记,引入样式表。
项目引用:
<div class="rig_fenye">
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" NumericButtonType="Text" ShowFirstLast="false" NumericButtonCount="6"
pagingbuttontype="Image" ImagePath="~/images/" ButtonImageNameExtension="n" ButtonImageExtension=".gif" CssClass="paginator" CurrentPageButtonClass="cpb"
DisabledButtonImageNameExtension="g" CpiButtonImageNameExtension="r" ShowPageIndexBox="Never" ButtonImageAlign="left" NextPrevButtonClass="npb" PagingButtonSpacing="0px" OnPageChanged="AspNetPager1_PageChanged"></webdiyer:aspnetpager>
</div>
注意:~/images/需要图片:
1,
2,
3,
4,
5,
6,
最后效果图:
还
最后,找到页面内的AspNetPager控件,添加CssClass CurrentPageButtonClass属性。
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页"
HorizontalAlign="Center" LastPageText="尾页" NextPageText="下一页"
onpagechanged="AspNetPager1_PageChanged" PageIndexBoxType="TextBox"
PageSize="7" PrevPageText="上一页" ShowPageIndexBox="Auto" SubmitButtonText="Go"
TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" UrlPaging="True" CssClass="paginator" CurrentPageButtonClass="cpb" >
</webdiyer:AspNetPager>
切换到视图模式或者在浏览器中查看该网页,是不是样式已经添加成功啦?
另附其他风格的几种样式,将样式引入网页后,请根据类选择器的名称不同配置控件的CssClass CurrentPageButtonClass属性。
网易风格:
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
属性设置:CssClass="anpager" CurrentPageButtonClass="cpb"
拍拍风格:
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
属性设置:CssClass="paginator" CurrentPageButtonClass="cpb"
迅雷风格:
.pages { color: #999; }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
CssClass="pages" CurrentPageButtonClass="cpb"