• GridView使用自带分页功能时分页方式及样式PagerStyle


    转向地址:http://www.bubuko.com/infodetail-412562.html

    GridView分页,使用自带分页功能,类似下面样式:

    在aspx页面中,GridView上的PagerStyle下CssClass属性,设置为bubufxPagerCss,具体aspx页面代码:

    <asp:GridView ID="GridView1" runat="server" Width="100%" AutoGenerateColumns="False"
                AllowPaging="True" EmptyDataText="没有数据记录!!" OnPageIndexChanging="GridView1_PageIndexChanging"
                ShowHeader="False" GridLines="None">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" />
                    <asp:BoundField DataField="name" HeaderText="name" />
                    <asp:BoundField DataField="card" HeaderText="card" />
                    <asp:TemplateField ItemStyle-HorizontalAlign="right" ItemStyle-CssClass="list" ItemStyle-Width="100">
                        <ItemTemplate>
                            <%# Eval("ctime", "{0:yyyy-MM-dd}")%>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PageButtonCount="5"
                    PreviousPageText="上一页" Mode="NumericFirstLast" />
                <PagerStyle BorderColor="#66FF66" Font-Names="宋体" Font-Size="12px" HorizontalAlign="Center"
                    CssClass="bubufxPagerCss" />
            </asp:GridView>
    

     px.cs代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    using System.Data.OleDb;
    using System.Data;
    
    public partial class list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dataBind();
            }
    
        }
    
    
        private void dataBind()
        {
            string sql = "select * from tt ";
    
            try
            {
                DataTable DT = new DataTable();
                //
                string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("db.mdb");
    
                OleDbConnection conn = new OleDbConnection(connStr);
    
                if (conn.State == ConnectionState.Closed) conn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
    
                da.Fill(DT);
                conn.Close();
                //
                
                GridView1.DataSource = DT;
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("数据库错误,错误原因:" + ex.Message);
                Response.End();
            }
        }
    
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            dataBind();
    
        }
    
    }
    

     css代码:

    .bubufxPagerCss table
    {
        text-align:center;
        margin:auto;
    }
    .bubufxPagerCss table td
    {
        border:0px;
        padding:5px;
    }
    .bubufxPagerCss td
    {
        border-left: #ffffff 3px solid;
        border-right: #ffffff 3px solid;
        border-bottom: #ffffff 3px solid;
    }
    .bubufxPagerCss a
    {
        color:#231815;text-decoration:none;padding:3px 6px 3px 6px; margin: 0 0 0 4px; text-align:center; border:1px solid #ac1f24;
    }
    .bubufxPagerCss span
    {
         color:#fefefe;background-color:#ac1f24; padding:3px 6px 3px 6px; margin: 0 0 0 4px; text-align:center; font-weight:bold; border:1px solid #ac1f24;
    }
    

    这样就实现自带分页的页码样式了。

  • 相关阅读:
    一个例子帮助理解正则表达式
    requestAnimationFrame兼容性扩展
    检测访问网页的浏览器呈现引擎、平台、Windows操作系统、移动设备和游戏系统
    手把手教你如何安装和使用Karma-Jasmine
    cesium随笔 — 隐藏三维场景下方版权信息
    cesium随笔 — 获取当前鼠标的经度、纬度、高度
    Cesium Language (CZML) 入门2 — CZML Content(CZML的内容)
    html初识
    MySQL终章
    MySQL表与表之间的关系详解
  • 原文地址:https://www.cnblogs.com/weekzero/p/3456225.html
Copyright © 2020-2023  润新知