主頁 > 知識庫 > asp.net自定義分頁控件示例

asp.net自定義分頁控件示例

熱門標(biāo)簽:400電話辦理信任翰諾科技 怎樣給陜西地圖標(biāo)注顏色 廣州銷售外呼系統(tǒng)定制 電銷機(jī)器人 數(shù)據(jù) 地圖標(biāo)注多少錢一張 云狐人工智能電話機(jī)器人 宿遷智能外呼系統(tǒng)排名 福州人工智能電銷機(jī)器人加盟 ai電銷機(jī)器人對貸款有幫助嗎

一、.ascx頁面

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

%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Pagination.ascx.cs" Inherits="IOCS.WEB.UserControl.Pagination" %>
link href="../Content/Css/Pager.css" rel="stylesheet" type="text/css" />
div id="tbPage" class="pager" runat="server" >
    記錄總數(shù):asp:Label ID="LRecords" runat="server">/asp:Label>
    總頁數(shù):asp:Label ID="LPages" runat="server">/asp:Label>
    當(dāng)前頁:asp:Label ID="LPage" runat="server">/asp:Label>

        asp:LinkButton ID="LinkFirst" runat="server" CommandArgument="first" nClick="PagerButtonClick"
            Text="首頁">/asp:LinkButton>

        asp:LinkButton ID="LinkPrevious" runat="server" CommandArgument="prev" nClick="PagerButtonClick"
            Text="上一頁">/asp:LinkButton>

        asp:LinkButton ID="LinkNext" runat="server" CommandArgument="next" nClick="PagerButtonClick"
            Text="下一頁">/asp:LinkButton>

        asp:LinkButton ID="LinkLast" runat="server" CommandArgument="last" nClick="PagerButtonClick"
            Text="末頁">/asp:LinkButton>
    轉(zhuǎn)到第asp:TextBox ID="txtpage"  CssClass="piut" runat="server"  MaxLength="5" AutoPostBack="True" nTextChanged="txtpage_TextChanged">/asp:TextBox>頁

二、.ascx.cs文件

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IOCS.WEB.UserControl
{
    public partial class Pagination : System.Web.UI.UserControl
    {
        public event EventHandler PageButtonClick;
        public bool FirstPost = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              

            }
            // 只輸入數(shù)字
            txtpage.Attributes.Add("onclick",
                @"if(!((event.keyCode>=48event.keyCode=57)
                    ||(event.keyCode>=96event.keyCode=105)
                    ||(event.keyCode==8)))event.returnValue=false;"
              );

        }
        GridView _gv;

        /// summary>
        /// 需要分頁的GridView
        /// /summary>
        public GridView TargetControlID
        {
            set
            {
                _gv = value;
            }
            get
            {
                return _gv;
            }
        }

        protected void PagerButtonClick(object sender, EventArgs e)
        {
            //獲得linkebutton的參數(shù)值
            string arg = ((LinkButton)sender).CommandArgument;
            switch (arg)
            {
                case ("next"):
                    {
                        if (_gv.PageIndex _gv.PageCount - 1)
                        {
                            _gv.PageIndex=_gv.PageIndex+1;
                        }
                        break;
                    }
                case ("prev"):
                    {
                        if (_gv.PageIndex > 0)
                        {
                            _gv.PageIndex--;
                        }
                        break;
                    }
                case ("first"):
                    {
                        _gv.PageIndex = 0;
                        break;
                    }
                case ("last"):
                    {
                        if (_gv.PageCount > 0)
                        {
                            _gv.PageIndex = _gv.PageCount - 1;
                        }
                        break;
                    }

                default:
                    {
                        _gv.PageIndex = Convert.ToInt32(arg);
                        break;
                    }
            }
            PageButtonClick(sender, e);

        }

        

        public void SetPageButton()
        {
            if (_gv.PageIndex == 0)
            {
                LinkFirst.Enabled = false;
                LinkPrevious.Enabled = false;


                LinkFirst.Style["color"] = "gray";
                LinkPrevious.Style["color"] = "gray";

                object s = LinkFirst.Style.Keys;
                if (_gv.PageCount > 1)
                {
                    LinkNext.Enabled = true;
                    LinkLast.Enabled = true;
                    txtpage.Enabled = true;
                    txtpage.Enabled = true;
                    LinkNext.Style["color"] = "#000";
                    LinkLast.Style["color"] = "#000";
                    txtpage.Style["readonly"] = "false";
                }
                else
                {
                    LinkNext.Enabled = false;
                    LinkLast.Enabled = false;
                    txtpage.Enabled = false;
                    LinkNext.Style["color"] = "gray";
                    LinkLast.Style["color"] = "gray";
                    txtpage.Style["readonly"] = "true";//background-color
                }
            }
            else if (_gv.PageIndex == _gv.PageCount - 1)
            {
                LinkFirst.Enabled = true;
                LinkPrevious.Enabled = true;
                LinkNext.Enabled = false;
                LinkLast.Enabled = false;
                LinkFirst.Style["color"] = "#000";
                LinkPrevious.Style["color"] = "#000";
                LinkNext.Style["color"] = "gray";
                LinkLast.Style["color"] = "gray";
            }
            else
            {
                LinkFirst.Enabled = true;
                LinkPrevious.Enabled = true;
                LinkNext.Enabled = true;
                LinkLast.Enabled = true;
                LinkFirst.Style["color"] = "#000";
                LinkPrevious.Style["color"] = "#000";
                LinkNext.Style["color"] = "#000";
                LinkLast.Style["color"] = "#000";
            }
        }

        /// summary>
        /// 設(shè)定頁面信息
        /// /summary>
        /// param name="dsCount">DataSet的紀(jì)錄總數(shù)/param>

        public void SetPageRecord(int dsCount)
        {
            LRecords.Text = dsCount.ToString();
            int mod= dsCount%_gv.PageSize;
            LPages.Text = (mod == 0 ? dsCount / _gv.PageSize : dsCount / _gv.PageSize + 1).ToString();
            LPage.Text = (_gv.PageIndex + 1).ToString();
            tbPage.Visible = true;
            SetPageButton();
        }

        protected void txtpage_TextChanged(object sender, EventArgs e)
        {
            if (txtpage.Text != "")
            {
                try
                {
                    int index = int.Parse(txtpage.Text.Trim());
                    if (index = _gv.PageCount index >= 1)
                    {
                        _gv.PageIndex = index - 1;
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "script. language='javascript'>alert('對不起,頁數(shù)超過索引范圍!');/script>");
                    }
                }
                catch
                {

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "script. language='javascript'>alert('對不起,只能輸入數(shù)字!');/script>");
                }
            }
            PageButtonClick(sender, e);
        }
    }
}

您可能感興趣的文章:
  • asp.net webform自定義分頁控件
  • asp.net分頁控件使用詳解【附實(shí)例下載】
  • 解析asp.net的分頁控件
  • 關(guān)于asp.net 自定義分頁控件
  • asp.net中使用自定義控件的方式實(shí)現(xiàn)一個分頁控件的代碼
  • 分享一個asp.net pager分頁控件
  • asp.net分頁控件AspNetPager的樣式美化
  • asp.net下Repeater使用 AspNetPager分頁控件
  • AspNetAjaxPager,Asp.Net通用無刷新Ajax分頁控件,支持多樣式多數(shù)據(jù)綁定
  • asp.net web頁面自定義分頁控件使用詳解

標(biāo)簽:黃南 綿陽 焦作 大興安嶺 曲靖 新疆 宜春 延安

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net自定義分頁控件示例》,本文關(guān)鍵詞  asp.net,自定義,分頁,控件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net自定義分頁控件示例》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net自定義分頁控件示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章