AspNetPager自定义分页控件样式

本文介绍了如何自定义AspNetPager分页控件的两种样式,包括带首页和尾页以及不带首页和尾页的样式,并展示了相应的CSS样式。同时,提供了后台数据绑定的方法,包括获取总页数、定制信息以及数据填充到GridView的操作。
摘要由CSDN通过智能技术生成

前台:

样式一(带首页和尾页):
 <wtl:pager pagesize="4" targetid="mylist" footer="5" isnullshow="true">
                   <div class="Page">             
                    共<a class="Page_Max">{$RecordsTotal}</a>条 <a class="Page_PageCount">{$PageTotal}</a>页 
                    <a class="Page_First" href="{$FirstPageUrl}">首页</a>
                    <a class="Page_Prev" href="{$PrevPageUrl}">上一页</a>
                    <a class="Page_Next" href="{$NextPageUrl}">下一页</a>
                    <a class="Page_End" href="{$LastPageUrl}">末页</a>
                    <input id='{$PageID}_input' value='{$CurrentPage}'  class="Page_Text" type="text"  />&nbsp;
                    <input id='{$PageID}_button' οnclick="redirectPage_{$PageID}('{$PageID}_input')" class="Page_Button" type="button" value="" />
                  </div>
               </wtl:pager>




样式二(不带首页和尾页)
<wtl:pager pagesize="4" targetid="mylist" footer="5" isnullshow="true">
                   <div class="Page">             
                    共有<a class="Page_PageCount">{$PageTotal}</a>页/当前位置:
                    <a class="Page_Prev" href="{$PrevPageUrl}">上一页</a>
                    <em class='num'>
                    <Numeric>
                       <a href='{$PageUrl}' class='{$PageNumClass}'  id='pageNum{$PageNum}'>{$PageNum}</a>
                    </Numeric>
                    </em>
                    <a class="Page_Next" href="{$NextPageUrl}">下一页</a>
                    <input id='{$PageID}_input' value='{$CurrentPage}'  class="Page_Text" type="text"  />&nbsp;
                    <input id='{$PageID}_button' οnclick="redirectPage_{$PageID}('{$PageID}_input')" class="Page_Button" type="button" value="" />
                  </div>
               </wtl:pager>
样式css:
/*page*/
.Page{text-align:right; padding:30px 0; clear:both; color:#4e4e4e;}
.Page a{ color:#4e4e4e; text-decoration:none;}
.Page .Page_Max{color:#c90d0d; margin:0 3px;}/*总条数*/
.Page .Page_PageCount{color:#c90d0d; margin:0 3px;}/*总页数*/
.Page .Page_First{}/*首页*/
.Page .Page_Prev{background:url(../images/page.gif) repeat-x; display:inline-block; width: 45px;height: 15px;line-height: 15px;text-align: center; border:1px solid #D7D7D7;}/*上一页*/
.Page .Page_Next{background:url(../images/page.gif) repeat-x; display:inline-block; width: 45px;height: 15px;line-height: 15px;text-align: center; border:1px solid #D7D7D7;}/*下一页*/
.Page .Page_End{}/*末页*/
.Page .Page_Text{ width:23px; height:15px; border-left:solid 1px #c5c5c5; border-top:solid 1px #c5c5c5; border-right:solid 1px #eaeaea; border-bottom:solid 1px #eaeaea; text-align:center;}/*页码文本框*/
.Page .Page_Button{ background:url(../images/GO.gif) no-repeat; width:30px; height:22px; font-size:12px; border:none; cursor:pointer;}/*按钮*/
.Page .num a{background:url(../images/page.gif) repeat-x; display:inline-block; width: 15px;height: 15px;line-height: 15px;text-align: center;border:1px solid #D7D7D7; margin-right:3px;}/*数字链接样式*/
.Page .a_cur{color:Red;}/*当前页选中*/


 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="1024px"
                EmptyDataText="没有数据" HorizontalAlign="Center" GridLines="None">
                <Columns>
                    <asp:BoundField DataField="Name" HeaderText="项目名称" />
                    <asp:BoundField DataField="Saler" HeaderText="销售工程师" />
                    <asp:BoundField DataField="SignDateTime" HeaderText="销售时间" />
                    <asp:BoundField DataField="Industry" HeaderText="行业类别" />
                    <asp:BoundField DataField="ProjectManager" HeaderText="项目经理" />
                      <asp:TemplateField HeaderText="测试域名">
                        <ItemTemplate>
                            <div style="overflow: auto; width: 140px; height: 60px; text-align: center; background:#fff;">
                                <br />
                                <%#Eval("TestSiteUrl")%>
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="正式域名">
                        <ItemTemplate>
                            <div style="overflow: auto; width: 140px; height: 60px; text-align: center; background:#fff;">
                                <br />
                                <%#Eval("Domain")%>
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>
 
                </Columns>
            </asp:GridView>
            
            <asp:AspNetPager PageSize="10" CurrentPageIndex="1" ID="AspNetPager1" runat="server"
                CssClass="paginator" CurrentPageButtonClass="cpb" OnPageChanged="AspNetPager1_PageChanged"
                FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left"
                ShowInputBox="Never" CustomInfoTextAlign="Left" LayoutType="Table">
            </asp:AspNetPager>


后台:

//绑定数据

private void BindData()
    {

 using (SqlConnection connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlserver"].ToString()))
        {
            SqlCommand cmd = new SqlCommand(" select count(*) from Whir_ProjectInfo where 1=1 " + SWhere + " ", connection);
            connection.Open();
            AspNetPager1.RecordCount = int.Parse(cmd.ExecuteScalar().ToString());//总的页数
            this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount, this.AspNetPager1.PageSize });
            cmd = new SqlCommand(SQL.ToString(), connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            connection.Close();
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }


}


 protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }


    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
    }






本人在网上一直没有找到自己想要的分页控件,要么界面不理想,功能不全、要么支持的浏览器不好、要么代码臃肿、效率低下、bug极多的诸如aspNetPager等控件居然连css也封装起来不让改而且写得很繁琐,其实我只要其中的一个功能样式,其他的我都不需要,而且在使用过程中大家可能也会遇到我这样的问题第一次控件加载的时候,默认必须要执行他的其中一个方法,害得我不得不采用变通的方式绕过该bug,而且就是出现最新的版本7.02。当然我非常佩服控件的作者的技术水平,尊重他的劳动成果和共享精神。希望他做得更好。大家在使用过程中有任何问题请与作者QQ: 18066799(Yekin-yu)联系,非常感谢您的反馈,让我们把他做得更好,更方便大家的使用。由于本人业余开发,时间仓促,使用中难免与个人的使用习惯及功能需求有不当的地方。欢迎指正。 功能特点:         一、支持网上流传的24种分页样式;       二、无限扩展自定义样式,灵活;       三、支持所有asp.net控件分页绑定; 四、分页效率高;       五、扩展方便、灵活性高;       六、支持所有浏览器,文档类型、兼容性高; 使用方法: /* 24种分页样式复制粘贴开始(名称不要变,只要复制内容即可)*/ ......pagerstyle.css里面的标记内容 /* 24种分页样式复制粘贴结束*/ 24种分页样式见目录!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值