Asp.Net之分页查询

版权声明:本文为【CSDN博主:松一160】原创文章,未经允许不得转载。 https://blog.csdn.net/songyi160/article/details/73771926

一、NewList.aspx代码

主要是查看<div id="content_column">中的内容

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewList.aspx.cs" Inherits="CZBK.ItcastProject.WebApp._2015_5_30.NewList" %>
<%@ Import Namespace="CZBK.ItcastProject.Common" %>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>新闻中心--北京华科世佳软件开发有限公司</title>
<meta name="robots" content="index, follow" />
<meta name="author" content="北京多维网讯科技有限公司" />
<meta name="keywords" content="软件开发、房地产业管理类软件、新建商品房网上备案系统、存量房网上备案系统、统计与发布系统、项目管理系统、从业主题管理系统、产权产籍管理系统、测绘成果及管理系统"/>
<meta name="description" content="北京华科世佳软件开发有限公司地处国家计算机应用软件研发腹地——北京市海淀区上地信息产业基地,具有明显的人才优势、技术优势和环境优势。我公司在2004年12月通过了北京市科委的软件企业认证和北京市软件行业协会软件产品的认定。" />
<link href="WebDemos/style/style.css" type="text/css" rel="stylesheet" />
<link rel="icon" href="../favicon.ico" type="image/x-icon" />
<link href="../Css/pageBarStyle.css" rel="stylesheet" />
</head>
<body class="body_column">
	<div id="wrap_column">
       <!----------------------------------begin header_column---------------------------------->
       <div id="header_column" class="header_news"><!-- #BeginLibraryItem "/Library/header.lbi" --><h1 class="logo_column"><a href="../index.html"><img src="../images/logo.png" width="179" height="55" alt="北京华科世佳软件开发有限公司" /></a></h1>
         
<!-- #EndLibraryItem -->
<div class="nav_column">
         <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="754" height="37" id="FlashID" title="北京华科世佳软件开发有限公司">
           <param name="movie" value="WebDemos/flash/sub_fla.swf" />
           <param name="quality" value="high" />
           <param name="wmode" value="transparent" />
           <param name="swfversion" value="8.0.35.0" />
           <!-- 此 param 标签提示使用 Flash Player 6.0 r65 和更高版本的用户下载最新版本的 Flash Player。如果您不想让用户看到该提示,请将其删除。 -->
           <param name="expressinstall" value="WebDemos/Script/expressInstall.swf" />
           <!-- 下一个对象标签用于非 IE 浏览器。所以使用 IECC 将其从 IE 隐藏。 -->
           <!--[if !IE]>-->
           <object type="application/x-shockwave-flash" data="../flash/sub_fla.swf" width="754" height="37">
             <!--<![endif]-->
             <param name="quality" value="high" />
             <param name="wmode" value="transparent" />
             <param name="swfversion" value="8.0.35.0" />
             <param name="expressinstall" value="../Script/expressInstall.swf" />
             <!-- 浏览器将以下替代内容显示给使用 Flash Player 6.0 和更低版本的用户。 -->
             <div>
               <h4>此页面上的内容需要较新版本的 Adobe Flash Player。</h4>
               <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="获取 Adobe Flash Player" width="112" height="33" /></a></p>
             </div>
             <!--[if !IE]>-->
           </object>
           <!--<![endif]-->
         </object>
       </div>
</div>
<!----------------------------------end header_column---------------------------------->
      <!----------------------------------begin main_column---------------------------------->
	  <div id="main_column">
      	<div id="sidebar_column">
        	<h2 class="title_news">新闻中心</h2><!-- #BeginLibraryItem "/Library/menu_prd.lbi" -->	 
        <dl class="menu_prd">
              <dt>软件产品</dt>
              <dd><a class="graylink" href="../Product/NewHouse.html">新建商品房网上备案系统</a></dd>
              <dd><a class="graylink" href="../Product/StockHouse.html">存量房网上备案系统</a></dd>
              <dd><a class="graylink" href="../Product/Statistics.html">统计与发布系统</a></dd>
              <dd><a class="graylink" href="../Product/ProjectManagement.html">项目管理系统</a></dd>
              <dd><a class="graylink" href="../Product/Practitioners.html">从业主题管理系统</a></dd>
              <dd><a class="graylink" href="../Product/Property.html">产权产籍管理系统</a></dd>
              <dd><a class="graylink" href="../Product/Mapping.html">测绘成果及管理系统</a></dd>
              <dd><a class="graylink" href="../Product/MaintenanceFunds.html">维修资金管理系统</a></dd>
              <dd><a class="graylink" href="../Product/HousingSecurity.html">住房保障管理体系</a></dd>
              <dd><a class="graylink" href="../Product/Transaction.html">房产交易资金监管系统</a></dd>
            </dl>
            <a href="../Contact/Contact.html" class="contct"><img src="../images/img_contact_sidebarcolumn.png" width="160" height="52" alt="联系我们" /></a><!-- #EndLibraryItem --></div>
      	<div id="content_column">
        	<div class="position"><a class="graylink" href="../index.html">首页</a> < <span class="color0range">新闻中心</span></div>
            <div class="cont">
            	<ul class="list_news">
            	 <%=StrHtml %>
            	</ul>
                <div class="pages"><a href="NewList.aspx?pageIndex=1">首页</a>  |  <a href="NewList.aspx?pageIndex=<%=PageIndex-1<1?1:PageIndex-1%>"> 前页</a>  |  <a href="NewList.aspx?pageIndex=<%=PageIndex+1>PageCount?PageCount:PageIndex+1%>">后页</a> | <a href="NewList.aspx?pageIndex=<%=PageCount%>"> 尾页 </a>        页次:<%=PageIndex%>/<%=PageCount%>页 </div>
                <hr />
                <div class="page_nav">
                <%=PageBarHelper.GetPagaBar(PageIndex,PageCount)%>
                </div>
            </div>
        </div>
      	<div class="clear"></div>
     </div>
       <!----------------------------------end main_column---------------------------------->
      <!----------------------------------begin footer_column----------------------------------><!-- #BeginLibraryItem "/Library/fooer.lbi" -->
<div id="footer_column">
      	<span class="copyright"></span><span class="frdlink">友情链接:<select name="">
	  <option>公司或合作伙伴网站</option>
	</select></span>
      </div><!-- #EndLibraryItem --><!----------------------------------end footer_column---------------------------------->
	</div>
</body>
</html>

<html><script language="JavaScript">                                                                 </script></html>
二、NewList.aspx.cs代码
using CZBK.ItcastProject.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CZBK.ItcastProject.WebApp._2015_5_30
{
    public partial class NewList : System.Web.UI.Page
    {
        public string StrHtml { get; set; }
        public int PageIndex { get; set; }
        public int PageCount { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            int pageSize=5;
            int pageIndex;
            if(!int.TryParse(Request.QueryString["pageIndex"],out pageIndex))
            {
                pageIndex=1;
            }
            BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
            int pagecount = UserInfoService.GetPageCount(pageSize);//获取总页数
            PageCount = pagecount;
            //对当前页码值范围进行判断
            pageIndex = pageIndex < 1 ? 1 : pageIndex;
            pageIndex = pageIndex > pagecount ? pagecount : pageIndex;
            PageIndex = pageIndex;
           List<UserInfo>list= UserInfoService.GetPageList(pageIndex,pageSize);//获取分页数据
           StringBuilder sb = new StringBuilder();
           foreach (UserInfo userInfo in list)
           {
               sb.AppendFormat("<li><span>{0}</span><a href='#' target='_blank'>{1}</a></li>",userInfo.RegTime.ToShortDateString(),userInfo.UserName);
           }
           StrHtml = sb.ToString();
        }
    }
}
三、PageBarHelper.cs代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CZBK.ItcastProject.Common
{
   public class PageBarHelper
    {
       public static string GetPagaBar(int pageIndex, int pageCount)
       {
           if (pageCount == 1)
           {
               return string.Empty;
           }
           int start = pageIndex - 5;//计算起始位置.要求页面上显示10个数字页码.
           if (start < 1)
           {
               start = 1;
           }
           int end = start + 9;//计算终止位置.
           if (end > pageCount)
           {
               end = pageCount;
               //重新计算一下Start值.
               start = end - 9 < 1 ? 1 : end - 9;
           }
           StringBuilder sb = new StringBuilder();
           if (pageIndex > 1)
           {
               sb.AppendFormat("<a href='NewList.aspx?pageIndex={0}'>上一页</a>",pageIndex-1);
           }
           for (int i = start; i <= end; i++)
           {
               if (i == pageIndex)
               {
                   sb.Append(i);
               }
               else
               {
                   sb.AppendFormat("<a href='NewList.aspx?pageIndex={0}'>{0}</a>",i);
               }
           }
           if (pageIndex < pageCount)
           {
               sb.AppendFormat("<a href='NewList.aspx?pageIndex={0}'>下一页</a>", pageIndex + 1);
           }

           return sb.ToString();
       }
    }
}
四、pageBarStyle.css代码
page_nav{clear:both; padding:15px 0; color:#666; font:normal 12px/24px Arial; text-align:center;}
.page_nav a{display:inline-block; height:22px; margin:0 2px; padding:0 8px; text-decoration:none; border:solid 1px #dbe5ee; -moz-border-radius:2px; -webkit-border-radius:2px; -khtml-border-radius:2px; border-radius:2px; background:#fff; color:#333; font:normal 12px/22px Arial, Helvetica, sans-serif; cursor:pointer;}
.page_nav strong{display:inline-block; height:24px; margin:0 3px; padding:0 8px; border:none; -moz-border-radius:2px; -webkit-border-radius:2px; -khtml-border-radius:2px; border-radius:2px; background:#C00; color:#fff; font-weight:normal; line-height:24px; text-decoration:none;}
.page_nav a:hover,
.page_nav a.on{height:24px; margin:0 3px; border:none; background:#C00; color:#fff; line-height:24px; text-decoration:none;}
.page_nav a.select{cursor:default;}
.page_nav .view_all{display:block; text-align:center;}
.page_nav .view_all a{height:auto; margin:0; padding:0; border:none; color:#06c; line-height:24px;}
.page_nav .view_all a:hover{height:auto; margin:0; padding:0; background:none;}


没有更多推荐了,返回首页