佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > AspNetPager+GridView實(shí)現(xiàn)分頁(yè)的實(shí)例代碼

AspNetPager+GridView實(shí)現(xiàn)分頁(yè)的實(shí)例代碼

熱門標(biāo)簽:Mysql連接數(shù)設(shè)置 團(tuán)購(gòu)網(wǎng)站 銀行業(yè)務(wù) 服務(wù)器配置 阿里云 電子圍欄 Linux服務(wù)器 科大訊飛語音識(shí)別系統(tǒng)

.框架是.NET Framework 4.0
.一共為三個(gè)部分: 前臺(tái)頁(yè)面設(shè)計(jì)代碼、前臺(tái)頁(yè)面程序代碼、css樣式
.其中數(shù)據(jù)庫(kù)連接操作用了DB類(連接語句),SQLHelper(微軟的數(shù)據(jù)庫(kù)操作類)
效果圖:


前臺(tái)頁(yè)面設(shè)計(jì)代碼

復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWebSite.Default" %>

%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
    title>/title>
    link href="Styles/Paging.css" rel="stylesheet" type="text/css" />
/head>
body>
    form id="form1" runat="server">
    div>

        asp:GridView ID="GridView1" runat="server" Height="261px" Width="737px"
            CellPadding="4" ForeColor="#333333" GridLines="None">
            AlternatingRowStyle BackColor="White" />
            EditRowStyle BackColor="#2461BF" />
            FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            HeaderStyle HorizontalAlign="Left" BackColor="#507CD1" Font-Bold="True"
                ForeColor="White" />
            PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            RowStyle BackColor="#EFF3FB" />
            SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            SortedAscendingCellStyle BackColor="#F5F7FB" />
            SortedAscendingHeaderStyle BackColor="#6D95E1" />
            SortedDescendingCellStyle BackColor="#E9EBEF" />
            SortedDescendingHeaderStyle BackColor="#4870BE" />
        /asp:GridView>

    /div>
    webdiyer:AspNetPager ID="AspNetPager1" runat="server"
        onpagechanged="AspNetPager1_PageChanged" CssClass="anpager"
        CurrentPageButtonClass="cpb" FirstPageText="首頁(yè)" LastPageText="尾頁(yè)"
        NextPageText="后頁(yè)" PrevPageText="前頁(yè)">
    /webdiyer:AspNetPager>
    /form>
/body>
/html>


 前臺(tái)頁(yè)面程序代碼
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestWebSite.Utilities;
using System.Data;
using System.Data.SqlClient;
using Wuqi.Webdiyer;

namespace TestWebSite
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //調(diào)用綁定分頁(yè)和GridView
                BindGridView();
            }
        }

        ////綁定分頁(yè)和GridView方法
        private void BindGridView()
        {
            //查詢語句
            string sequal = "select StandardName as 標(biāo)準(zhǔn)名稱, MakeUpItem as 補(bǔ)償項(xiàng)目, Unit as 單位,"
                + " cast(UnitPrice as decimal(18,2)) as 單價(jià), cast(StandRate as decimal(18,2)) as "
                + "成新率, Type as 分類 from Standard";
            //獲取數(shù)據(jù)表格
            DataTable dt =
                SqlHelper.ExecuteDataset(DB.con, CommandType.Text, sequal).Tables[0];
            //初始化分頁(yè)數(shù)據(jù)源實(shí)例
            PagedDataSource pds = new PagedDataSource();
            //設(shè)置總行數(shù)
            AspNetPager1.RecordCount = dt.Rows.Count;
            //設(shè)置分頁(yè)的數(shù)據(jù)源
            pds.DataSource = dt.DefaultView;
            //設(shè)置當(dāng)前頁(yè)
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            //設(shè)置每頁(yè)顯示頁(yè)數(shù)
            pds.PageSize = AspNetPager1.PageSize;
            //啟用分頁(yè)
            pds.AllowPaging = true;
            //設(shè)置GridView的數(shù)據(jù)源為分頁(yè)數(shù)據(jù)源
            GridView1.DataSource = pds;
            //綁定GridView
            GridView1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            //調(diào)用綁定分頁(yè)和GridView
            BindGridView();
        }
    }
}


 CSS樣式
復(fù)制代碼 代碼如下:

.anpager
{
    font: 11px Arial, Helvetica, sans-serif;
    padding:10px 20px 10px 0;
    margin: 0px;
}
.anpager a
{
    padding: 1px 6px;
    border: solid 1px #ddd;
    background: #fff;
    text-decoration: none;
    margin-right:2px
}
.anpager a:visited
{
    padding: 1px 6px;
    border: solid 1px #ddd;
    background: #fff;
    text-decoration: none;
}
.anpager .cpb
{
    padding: 1px 6px;
    font-weight: bold;
    font-size: 13px;
    border:none
}
.anpager a:hover
{
    color: #fff;
    background: #ffa501;
    border-color:#ffa501;
    text-decoration: none;
}

/* AspNetPager1屬性設(shè)置: CssClass="anpager" CurrentPageButtonClass="cpb"*/

您可能感興趣的文章:
  • asp.net gridview分頁(yè):第一頁(yè) 下一頁(yè) 1 2 3 4 上一頁(yè) 最末頁(yè)
  • asp.net中的GridView分頁(yè)問題
  • Android入門之ActivityGroup+GridView實(shí)現(xiàn)Tab分頁(yè)標(biāo)簽的方法
  • GridView分頁(yè)的實(shí)現(xiàn)以及自定義分頁(yè)樣式功能實(shí)例
  • Android中實(shí)現(xiàn)多行、水平滾動(dòng)的分頁(yè)的Gridview實(shí)例源碼
  • Asp.net GridView使用大全(分頁(yè)實(shí)現(xiàn))
  • GridView分頁(yè)的實(shí)現(xiàn)(通用分頁(yè)模板)
  • asp.net中g(shù)ridview的查詢、分頁(yè)、編輯更新、刪除的實(shí)例代碼
  • GridView高效分頁(yè)和搜索功能的實(shí)現(xiàn)代碼
  • 解析GridView自帶分頁(yè)及與DropDownList結(jié)合使用

標(biāo)簽:廣元 棗莊 萍鄉(xiāng) 衡水 江蘇 衢州 蚌埠 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《AspNetPager+GridView實(shí)現(xiàn)分頁(yè)的實(shí)例代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    千阳县| 九龙坡区| 茶陵县| 平原县| 酒泉市| 轮台县| 通辽市| 天镇县| 呈贡县| 新密市| 和田县| 都江堰市| 邵阳市| 赣榆县| 阳东县| 准格尔旗| 兴海县| 博罗县| 霍邱县| 庐江县| 建阳市| 武清区| 台中县| 永新县| 景宁| 辰溪县| 兴化市| 化德县| 扬中市| 安庆市| 镇安县| 舟曲县| 新宁县| 滕州市| 互助| 南漳县| 黄大仙区| 赤峰市| 三河市| 广元市| 祁阳县|