首页 > 编程 > .NET > 正文

asp.net自定义分页控件示例

2024-07-10 12:43:50
字体:
来源:转载
供稿:网友

一、.ascx页面

代码如下:
<%@ 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" >
    記錄總數:<asp:Label ID="LRecords" runat="server"></asp:Label>
    總頁數:<asp:Label ID="LPages" runat="server"></asp:Label>
    當前頁:<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>
    轉到第<asp:TextBox ID="txtpage"  CssClass="piut" runat="server"  MaxLength="5" AutoPostBack="True" nTextChanged="txtpage_TextChanged"></asp:TextBox>頁

二、.ascx.cs文件

代码如下:
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)
            {
              

            }
            // 只輸入數字
            txtpage.Attributes.Add("onclick",
                @"if(!((event.keyCode>=48&&event.keyCode<=57)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表