zoukankan      html  css  js  c++  java
  • DataGrid 超强分页(原创)

    aspx文件

    =============================

    <%@ Page language="c#" Codebehind="userlist.aspx.cs" AutoEventWireup="false" Inherits="admin.userlist" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
        
    <HEAD>
            
    <title>userlist</title>
            
    <meta content=" Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            
    <meta content="C#" name="CODE_LANGUAGE">
            
    <meta content="JavaScript" name="vs_defaultClientScript">
            
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            
    <LINK href="../images/css_admin.css" type="text/css" rel="stylesheet">
        
    </HEAD>
        
    <body bgColor="#ffeef7">
            
    <%=script%>
            
    <form id="Form1" method="post" runat="server">
                
    <div align="center">
                    
    <table cellSpacing="0" cellPadding="0" width="100%" border="0">
                        
    <tr>
                            
    <td width="100%">
                                
    <div align="center">
                                    
    <table height="20" cellSpacing="0" cellPadding="0" width="100%" bgColor="#d6e7ef" border="0">
                                        
    <tr>
                                            
    <td width="100%">
                                                
    <hr width="90%" SIZE="1">
                                            
    </td>
                                        
    </tr>
                                    
    </table>
                                
    </div>
                            
    </td>
                        
    </tr>
                    
    </table>
                
    </div>
                
    <DIV align="center">注册会员管理:</DIV>
                
    <div align="center">
                    
    <table height="40" cellSpacing="0" cellPadding="0" width="96%" border="0">
                        
    <tr>
                            
    <td align="center" width="100%">会员搜索:
                                
    <asp:dropdownlist id="DdlSearchType" runat="server" Height="16px" Width="110px">
                                    
    <asp:LIstItem Value="1">按会员名称搜索</asp:LIstItem>
                                    
    <asp:ListItem Value="2">按会员ID搜索</asp:ListItem>
                                
    </asp:dropdownlist><asp:textbox id="TxtSearchValue" runat="server"></asp:textbox>&nbsp;&nbsp;
                                
    <asp:button id="BtnSub" runat="server" Text="提交"></asp:button></td>
                        
    </tr>
                    
    </table>
                
    </div>
                
    <div align="center"><asp:datagrid id="DgUserList" runat="server" Width="96%" AllowPaging="True" PageSize="30" PagerStyle-HorizontalAlign="Right"
                        PagerStyle-Height
    ="30" HeaderStyle-Height="25" ItemStyle-Height="25" AutoGenerateColumns="False" BorderColor="Firebrick"
                        BorderWidth
    ="1px" CellPadding="0">
                        
    <AlternatingItemStyle BackColor="Azure"></AlternatingItemStyle>
                        
    <ItemStyle Height="25px"></ItemStyle>
                        
    <HeaderStyle HorizontalAlign="Center" Height="25px" BackColor="LightPink"></HeaderStyle>
                        
    <Columns>
                            
    <asp:TemplateColumn HeaderText="是否交费">
                                
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                
    <ItemTemplate>
                                    
    <%# DataBinder.Eval(Container.DataItem, "SFJFSORTNAME")%>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                            
    <asp:TemplateColumn HeaderText="注册会员ID">
                                
    <ItemTemplate>
                                    
    <%# DataBinder.Eval(Container.DataItem, "YJSID")%>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                            
    <asp:TemplateColumn HeaderText="姓名">
                                
    <ItemTemplate>
                                    
    <%# DataBinder.Eval(Container.DataItem, "YJSNAME")%>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                            
    <asp:TemplateColumn HeaderText="类别">
                                
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                
    <ItemTemplate>
                                    
    <%# DataBinder.Eval(Container.DataItem, "YJSSORTNAME")%>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                            
    <asp:TemplateColumn HeaderText="加入时间">
                                
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                
    <ItemTemplate>
                                    
    <%# DataBinder.Eval(Container.DataItem, "REGTIME")%>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                            
    <asp:TemplateColumn HeaderText="操作">
                                
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                
    <ItemTemplate>
                                    
    <href='UserMod.aspx?yjsid=<%# DataBinder.Eval(Container.DataItem, "YJSID")%>'>更改</a>
                                
    </ItemTemplate>
                            
    </asp:TemplateColumn>
                        
    </Columns>
                        
    <PagerStyle Height="30px" HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
                    
    </asp:datagrid></div>
                
    <div align="center">
                    
    <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="96%" align="center" bgColor="#ffffff"
                        border
    ="0">
                        
    <TR>
                            
    <TD align="center" height="30">记录数:
                                
    <asp:label id="LblRecordCount" runat="server">记录数</asp:label>;页次:
                                
    <asp:label id="LblCurrentIndex" runat="server">当前页</asp:label>/
                                
    <asp:label id="LblPageCount" runat="server">总页数</asp:label>; 【<asp:linkbutton id="BtnFirst" CommandArgument="first" runat="server">首页</asp:linkbutton>】 
                                【
    <asp:linkbutton id="BtnPrev" CommandArgument="prev" runat="server">上一页</asp:linkbutton><%=prev%>】 
                                【
    <asp:linkbutton id="BtnNext" CommandArgument="next" runat="server">下一页</asp:linkbutton><%=next%>】 
                                【
    <asp:linkbutton id="BtnLast" CommandArgument="last" runat="server">尾页</asp:linkbutton>】 
                                跳转:
    <asp:TextBox id="TxtJump" runat="server" Width="30px"></asp:TextBox>&nbsp;
                                
    <asp:Button id="BtnJumpSub" runat="server" Width="30px" Text="GO" Height="22px"></asp:Button>
                            
    </TD>
                        
    </TR>
                    
    </TABLE>
                
    </div>
            
    </form>
            
    <br>
            
    <br>
        
    </body>
    </HTML>


    ===========================================

    cs文件
    ===========================================

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using DataAccess;
    using Entity;

    namespace admin
    {
        
    /// <summary>
        
    /// userlist 的摘要说明。
        
    /// </summary>

        public class userlist : System.Web.UI.Page
        
    {
            
    protected System.Web.UI.WebControls.DropDownList DdlSearchType;
            
    protected System.Web.UI.WebControls.Button BtnSub;
            
    protected System.Web.UI.WebControls.DataGrid DgUserList;
            
    protected System.Web.UI.WebControls.Label LblRecordCount;
            
    protected System.Web.UI.WebControls.Label LblCurrentIndex;
            
    protected System.Web.UI.WebControls.Label LblPageCount;
            
    protected System.Web.UI.WebControls.LinkButton BtnFirst;
            
    protected System.Web.UI.WebControls.LinkButton BtnPrev;
            
    protected System.Web.UI.WebControls.LinkButton BtnNext;
            
    protected System.Web.UI.WebControls.LinkButton BtnLast;
            
    protected System.Web.UI.WebControls.TextBox TxtSearchValue;
            
    protected int RecordCount;//记录总数
            protected int PageCount;//页面总数
            protected string prev;
            
    protected string next;
            
    protected System.Web.UI.WebControls.TextBox TxtJump;
            
    protected System.Web.UI.WebControls.Button BtnJumpSub;
            
    protected string script;
        
            
    private void Page_Load(object sender, System.EventArgs e)
            
    {
                
    // 在此处放置用户代码以初始化页面
                
    //-管理员判断----------------------------------
                HttpCookie cokAdminName=new HttpCookie("CokAdminName");
                HttpCookie cokAdminPs
    =new HttpCookie("CokAdminPs");
                cokAdminName
    =Request.Cookies["CokAdminName"];
                cokAdminPs
    =Request.Cookies["CokAdminPs"];
                AdminLogin adLog
    =new AdminLogin(cokAdminName.Value ,cokAdminPs.Value );
                
    if(!adLog.login())
                
    {
                    Response.Redirect(
    "adminloginerror.aspx",true);
                }
                        
                
    //----------------------------------------------

                
    if(!Page.IsPostBack)
                
    {
                    
    this.DispUserList();
                    
    this.ShowStats();
                }

            }

            

            
    //-DATAGRID链接事件------------------------------------------------------------------------------
            private void DgUserList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
            
    {
                
    this.DgUserList.CurrentPageIndex=e.NewPageIndex;
                
    this.DispUserList();
                
    this.ShowStats();

            }

            
    //------------------------------------------------------------------------------------------------

            
    //-PageBtn_Click()事件--------------------------------------------------------------------------
            private void PageBtn_Click(object sender, System.EventArgs e)
            
    {
                
    string btn=((LinkButton)sender).CommandArgument.ToString();
                
    switch(btn)
                
    {
                    
    case "first":
                        
    this.DgUserList.CurrentPageIndex=0;
                        
    break;
                    
    case "last":
                        
    if(this.DgUserList.PageCount==0)
                        
    {
                            
    this.DgUserList.CurrentPageIndex=this.DgUserList.PageCount;
                        }

                        
    else
                        
    {
                            
    this.DgUserList.CurrentPageIndex=this.DgUserList.PageCount-1;
                        }

                        
    break;
                    
    case "prev":
                        
    this.DgUserList.CurrentPageIndex-=1;
                        
    break;
                    
    case "next":
                        
    this.DgUserList.CurrentPageIndex+=1;
                        
    break;
                }

                
    this.DispUserList();
                
    this.ShowStats();        
            }

            
    //------------------------------------------------------------------------------------------------

            
    //-跳转页面事件------------------------------------------------------------------------------
            private void BtnJumpSub_Click(object sender, System.EventArgs e)
            
    {
                
    try
                
    {
                    
    if(System.Convert.ToInt32(this.TxtJump.Text.ToString())<0||System.Convert.ToInt32(this.TxtJump.Text.ToString())>this.DgUserList.PageCount)
                    
    {
                        script
    +="<script language=javascript>alert('请输入正确的页数!')</script>";
                        
    this.DispUserList();
                        
    this.ShowStats();
                        
    this.TxtJump.Text="";
                    }

                    
    else
                    
    {
                        
    this.DgUserList.CurrentPageIndex=System.Convert.ToInt32(this.TxtJump.Text.ToString())-1;
                        
    this.DispUserList();
                        
    this.ShowStats();
                    }

                }

                
    catch
                
    {
                    script
    +="<script language=javascript>alert('请输入正确的页数!')</script>";
                    
    this.DispUserList();
                    
    this.ShowStats();
                    
    this.TxtJump.Text="";
                }


            }

            
    //-------------------------------------------------------------------------------------------

            
            
    //-搜索事件-----------------------------------------------------------------------------------------
            private void BtnSub_Click(object sender, System.EventArgs e)
            
    {
                
    this.DgUserList.CurrentPageIndex=0;
                
    this.DispUserList();
                
    this.ShowStats();
            }

            
    //--------------------------------------------------------------------------------------------------

            
    //-绑定DataGrid,DispUserList()---------------------------------------------
            public void DispUserList()
            
    {
                DataSet ds
    =OracleSelect.GetUserList(System.Convert.ToInt32(this.DdlSearchType.SelectedItem.Value.ToString()),this.TxtSearchValue.Text.ToString());
                
    if(ds.Tables.Count>0)
                
    {
                    
    if(ds.Tables[0].Rows.Count>0)
                    
    {
                        
    this.DgUserList.DataSource=ds;
                        
    this.DgUserList.DataBind();
                        
    this.RecordCount=ds.Tables[0].Rows.Count;//计算记录总数
                    }

                    
    else
                    
    {
                        
    this.script+="<script language=javascript>alert('sorry,没有找到相关记录!')</script>";
                    }

                }


            }

            
    //----------------------------------------------------------

            
    //-统计记录 ShowStats()-------------------------------------------------
            public void ShowStats()
            
    {
                
    this.LblRecordCount.Text=this.RecordCount.ToString();
                
    this.LblCurrentIndex.Text=(this.DgUserList.CurrentPageIndex+1).ToString();
                
    this.LblPageCount.Text=this.DgUserList.PageCount.ToString();
                
    this.PageCount=this.DgUserList.PageCount;//计算页面总数
                this.ShowPrevNext((this.DgUserList.CurrentPageIndex+1),this.DgUserList.PageCount);
            }



            
    //-是否显示上一页,下一页链接ShowPrevNext()----------------------------------------------------------------------
            public void ShowPrevNext(int currentPage,int pageCount)
            
    {
                
    if(pageCount==1)
                
    {
                    
    this.prev="<font color=888888>上一页</font>";
                    
    this.next="<font color=888888>下一页</font>";
                    
    this.BtnPrev.Visible=false;
                    
    this.BtnNext.Visible=false;
                }

                
    else
                
    {
                    
    if(currentPage==1)
                    
    {
                        
    this.prev="<font color=888888>上一页</font>";
                        
    this.BtnPrev.Visible=false;
                        
    this.next="";
                        
    this.BtnNext.Visible=true;
                    }

                    
    else
                    
    {
                        
    if(currentPage==this.PageCount)
                        
    {
                            
    this.next="<font color=888888>下一页</font>";
                            
    this.BtnNext.Visible=false;
                            
    this.prev="";
                            
    this.BtnPrev.Visible=true;
                        }

                        
    else
                        
    {
                            
    this.prev="";
                            
    this.next="";
                            
    this.BtnPrev.Visible=true;
                            
    this.BtnNext.Visible=true;
                        }

                    }

                }

            }

            
    //-------------------------------------------------------------------------------------------------


            
    Web 窗体设计器生成的代码

        }

    }

    ===============================

  • 相关阅读:
    Android中Context具体解释 ---- 你所不知道的Context
    JDK6、Oracle11g、Weblogic10 For Linux64Bit安装部署说明
    matplotlib 可视化 —— 定制 matplotlib
    matplotlib 可视化 —— 移动坐标轴(中心位置)
    matplotlib 可视化 —— 移动坐标轴(中心位置)
    matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
    matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
    指数函数的研究
    指数函数的研究
    指数分布的研究
  • 原文地址:https://www.cnblogs.com/ami/p/454554.html
Copyright © 2011-2022 走看看