zoukankan      html  css  js  c++  java
  • GRIDVIEW分页用户控件

    前台:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs" Inherits="e_booking_English_UserControls_Pager" %>
    <div style="text-align: right; padding-right: 30px">
        每页<asp:Label ID="pagesize" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageSize %>'
            Style="padding-right: 3px; padding-left: 3px"></asp:Label>项 共<asp:Label ID="rowscount"
                runat="server" Text='<%# ((GridView)Container.Parent.Parent).Rows.Count %>' Style="padding-right: 3px;
                padding-left: 3px"></asp:Label>项
        <asp:LinkButton ID="cmdFirstPage" runat="server" CommandName="Page" CommandArgument="First"
            Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
        <asp:LinkButton ID="cmdPreview" runat="server" CommandArgument="Prev" CommandName="Page"
            Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">前页</asp:LinkButton>
        第<asp:Label ID="lblcurPage" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1%>'
            Style="padding-right: 3px; padding-left: 3px"></asp:Label>页/共<asp:Label ID="lblPageCount"
                runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' Style="padding-right: 3px;
                padding-left: 3px"></asp:Label>页
        <asp:LinkButton ID="cmdNext" runat="server" CommandName="Page" CommandArgument="Next"
            Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">后页</asp:LinkButton>
        <asp:LinkButton ID="cmdLastPage" runat="server" CommandArgument="Last" CommandName="Page"
            Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
        转到<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CausesValidation="false"
            OnSelectedIndexChanged="DropPageChanged" OnDataBinding="DropDownList1_DataBinding">
        </asp:DropDownList>
        页
    </div>

    后台:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class e_booking_English_UserControls_Pager : System.Web.UI.UserControl
    {
        public GridView grd
        {
            get
            {
                GridView grd = Parent.Parent.NamingContainer as GridView;
                return grd;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {

        }
        protected void DropPageChanged(object sender, EventArgs e)
        {
            DropDownList DropDownList1 = sender as DropDownList;
            grd.PageIndex = int.Parse(DropDownList1.SelectedValue);
        }
        protected void DropDownList1_DataBinding(object sender, EventArgs e)
        {
            for (int i = 1; i <= grd.PageCount; i++)
            {
                DropDownList1.Items.Add(new ListItem(i + "/" + grd.PageCount, (i - 1).ToString()));
            }
            DropDownList1.SelectedIndex = grd.PageIndex;
        }
    }

  • 相关阅读:
    MySQL 常见问题
    Gym 101652P:Fear Factoring 数论
    万网域名查询接口(API)的说明
    在ashx页面获取Session值
    asp.net 操作xml
    用SQL进行嵌套查询
    在IE下 javascript比较两个字符串(包括中文汉字)是否相等
    asp.net中protected/private/public的用法与区别
    第一个
    解决IDEA Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA问题的一种方法。
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551968.html
Copyright © 2011-2022 走看看