日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
JQuery實(shí)現(xiàn)分頁(yè)程序代碼

做Web開發(fā)的程序員,分頁(yè)時(shí)在所難免的,微軟GridView、AspPager等設(shè)置分頁(yè)數(shù)據(jù)可以自動(dòng)分頁(yè),但是這里瀏覽器會(huì)閃動(dòng),用戶體驗(yàn)不是很友好,在此我整理了JQuery實(shí)現(xiàn)分頁(yè),并且使用。

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的丹寨網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

JQuery綁定模板,顯示數(shù)據(jù)

首先Default.aspx頁(yè)面需要引用的JS文件

JQuery采用 1.4.1.1 下載地址:http://pan.baidu.com/share/link?shareid=3024434948&uk=2920032010

JQuery數(shù)據(jù)顯示模板JS 下載地址:http://pan.baidu.com/share/link?shareid=3030793948&uk=2920032010

分頁(yè)按鈕樣式 下載地址:http://pan.baidu.com/share/link?shareid=3146737028&uk=2920032010

Default.aspx頁(yè)面js代碼,如下,每頁(yè)條數(shù)可以自定義,也可以放置配置文件中,queryString函數(shù)是根據(jù)URL參數(shù)名稱,獲取參數(shù)的值

 
 
 

Default.aspx頁(yè)面Form代碼如下,頁(yè)面數(shù)據(jù)使用JQuery jTemplates綁定數(shù)據(jù),非常方便,只需設(shè)置JSON格式數(shù)據(jù),引用JS文件即可

 
 
 
  1.             
  2.             
  3.                 
  4.                     
  5.                     ID
  6.                     姓名
  7.                     年齡
  8.                     
  9.                
  10.             
  11.             
  12.     {#foreach $T.table as record}
  13.     
  14.         
  15.             
  16.         
  17.         {$T.record.Id}
  18.         
  19.             {$T.record.Name}
  20.         
  21.         
  22.             {$T.record.Age}
  23.         
  24.     
  25.     {#/for}
  26.             
  27.      
  28.     
  29.     
  •     
  •     
  • $T.record.Id 中Id對(duì)應(yīng)的是實(shí)體類Id屬性

    #p#

    上面Javascript方法中用到Member_Ajax.aspx頁(yè)面代碼如下,注意:這里是將數(shù)據(jù)已JSON格式輸出到頁(yè)面,配合JQuery數(shù)據(jù)模板使用,所有Member_Ajax.aspx頁(yè)面,不應(yīng)該包含Html標(biāo)簽,其代碼格式如下

     
     
     
    1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Member_Ajax.aspx.cs" Inherits="Nick.Kuang.Web.Member_Ajax" %>

    Member_Ajax.aspx cs頁(yè)面代碼

     
     
     
    1. protected void Page_Load(object sender, EventArgs e)
    2.         {
    3.             Response.Write(GetAll());
    4.         }
    5.         private string GetAll()
    6.         {
    7.             List list = new List();
    8.             for (int i = 0; i < 100; i++)
    9.             {
    10.                 list.Add(new Student { Id = i, Name = "Name" + i, Age = i });
    11.             }
    12.             
    13.             int pageIndex = GetPage();
    14.             int pageSize = StrToInt(QueryString("pagesize"), 10); ;
    15.             JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer();
    16.             string result = javascriptSerializer.Serialize(list.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
    17.             string response = "{\"result\" :\"1\"," +
    18.                 "\"returnval\" :\"操作成功\"," +
    19.                 "\"pagebar\" :\"" + PageBar.GetPageBar(3, "js", 2, list.Count, pageSize, pageIndex, "javascript:ajaxList(<#page#>);") + "\"," +
    20.                "\"" + "totalCountStr" + "\":" + 10 + ",\"" + "table" + "\":" + result + 
    21.                 "}";
    22.             return response;
    23.         }
    24.         private static int GetPage()
    25.         {
    26.             int page = StrToInt(QueryString("pageIndex"), 0) < 1 ? 1 : StrToInt(QueryString("pageIndex"), 0);
    27.             return page;
    28.         }
    29.         private static int StrToInt(string value, int defaultValue)
    30.         {
    31.             if (IsNumeric(value))
    32.                 return int.Parse(value);
    33.             else
    34.                 return defaultValue;
    35.         }
    36.         /// 
    37.         /// 獲取querystring
    38.         /// 
    39.         /// 參數(shù)名
    40.         /// 返回值
    41.         private static string QueryString(string s)
    42.         {
    43.             if (HttpContext.Current.Request.QueryString[s] != null && HttpContext.Current.Request.QueryString[s] != "")
    44.             {
    45.                 return SafetyQueryS(HttpContext.Current.Request.QueryString[s].ToString());
    46.             }
    47.             return string.Empty;
    48.         }
    49.         /// 
    50.         /// 將字符串中的一些標(biāo)簽過(guò)濾
    51.         /// 
    52.         /// 
    53.         /// 
    54.         private static string SafetyQueryS(string theString)
    55.         {
    56.             string[] aryReg = { "'", ";", "\"", "\r", "\n", "<", ">" };
    57.             for (int i = 0; i < aryReg.Length; i++)
    58.             {
    59.                 theStringtheString = theString.Replace(aryReg[i], string.Empty);
    60.             }
    61.             return theString;
    62.         }
    63.         private static bool IsNumeric(string value)
    64.         {
    65.             System.Text.RegularExpressions.Regex myRegex = new System.Text.RegularExpressions.Regex("^[-]?[1-9]*[0-9]*$");
    66.             if (value.Length == 0)
    67.             {
    68.                 return false;
    69.             }
    70.             return myRegex.IsMatch(value);
    71.         }

    使用JavaScriptSerializer中的Serialize方法可以將Object類型數(shù)據(jù)轉(zhuǎn)換成JSON格式的數(shù)據(jù),告別以前拼接成字串的方法

    Student實(shí)體類代碼屬性

     
     
     
    1. public class Student
    2.     {
    3.         public int Id { get; set; }
    4.         public string Name { get; set; }
    5.         public int Age { get; set; }
    6.     }

    #p#

    分頁(yè)中用到的PageBar類代碼,分頁(yè)調(diào)用Default.aspx中ajaxList函數(shù),實(shí)現(xiàn)無(wú)刷新分頁(yè)

     
     
     
    1. public class PageBar
    2.     {
    3.         /// 
    4.         /// 完整模式:數(shù)字+上下頁(yè)+首末+總記錄信息+指定頁(yè)碼翻轉(zhuǎn)
    5.      /// 
    6.         /// 
    7.         /// 
    8.         /// 
    9.         /// 
    10.         /// 
    11.         /// 
    12.         /// 
    13.         /// 
    14.         /// 
    15.         /// 
    16.         /// 
    17.         private static string GetDetailbar(string stype, int stepNum, int pageRoot, int pageFoot, int pageCount, int countNum, int pageSize, int currentPage, string Http1, string HttpM, string HttpN, int limitPage)
    18.         {
    19.             StringBuilder sb = new StringBuilder();
    20.             sb.Append("");
    21.             //sb.Append("共" + countNum.ToString() + "條,當(dāng)前第" + currentPage.ToString() + "/" + pageCount.ToString() + "頁(yè)   ");
    22.             sb.Append("共" + countNum.ToString() + "條記錄/" + pageCount.ToString() + "頁(yè)  ");
    23.             if (countNum > pageSize)
    24.             {
    25.                 if (currentPage != 1)//只要不是***頁(yè)
    26.                     sb.Append("«");
    27.                 if (pageRoot > 1)
    28.                 {
    29.                     sb.Append("1..");
    30.                 }
    31.                 if (stepNum > 0)
    32.                 {
    33.                     for (int i = pageRoot; i <= pageFoot; i++)
    34.                     {
    35.                         if (i == currentPage)
    36.                             sb.Append("" + i.ToString() + "");
    37.                         else
    38.                             sb.Append("" + i.ToString() + "");
    39.                         if (i == pageCount)
    40.                             break;
    41.                     }
    42.                 }
    43.                 if (pageFoot < pageCount)
    44.                 {
    45.                     sb.Append(".." + pageCount + "");
    46.                 }
    47.                 if (currentPage != pageCount)//只要不是***一頁(yè)
    48.                     sb.Append("»");
    49.                 if (stype == "html")
    50.                     sb.Append("轉(zhuǎn)到第 ',this.value); return false;}\" /> 頁(yè)");
    51.             }
    52.             sb.Append("
    ");
  •             return sb.ToString();
  •         }
  •         /// 
  •         /// 分頁(yè)導(dǎo)航
  •         /// 
  •         /// 支持1=simple,2=normal,3=full
  •         /// html/js,只有當(dāng)stype為html且mode為3的時(shí)候顯示任意頁(yè)的轉(zhuǎn)向
  •         /// 步數(shù),如果步數(shù)為i,則每頁(yè)的數(shù)字導(dǎo)航就有2i+1
  •         /// 記錄總數(shù)
  •         /// 每頁(yè)記錄數(shù)
  •         /// 當(dāng)前頁(yè)碼
  •         /// 第1頁(yè)的鏈接地址模板,支持js
  •         /// 第M頁(yè)的鏈接地址模板,支持js,M不大于limitPage
  •         /// 第N頁(yè)的鏈接地址模板,支持js,N大于limitPage
  •         /// 
  •         /// 
  •         public static string GetPageBar(int mode, string stype, int stepNum, int countNum, int pageSize, int currentPage, string Http1, string HttpM, string HttpN, int limitPage)
  •         {
  •             string pagebar = "";
  •             //if (countNum > pageSize)
  •             //{
  •             int pageCount = countNum % pageSize == 0 ? countNum / pageSize : countNum / pageSize + 1;
  •             currentPage = currentPage > pageCount ? pageCount : currentPage;
  •             currentPage = currentPage < 1 ? 1 : currentPage;
  •             int stepageSize = stepNum * 2;
  •             int pageRoot = 1;
  •             int pageFoot = pageCount;
  •             pageCount = pageCount == 0 ? 1 : pageCount;
  •             if (pageCount - stepageSize < 1)//頁(yè)數(shù)比較少
  •             {
  •                 pageRoot = 1;
  •                 pageFoot = pageCount;
  •             }
  •             else
  •             {
  •                 pageRoot = currentPage - stepNum > 1 ? currentPage - stepNum : 1;
  •                 pageFoot = pageRoot + stepageSize > pageCount ? pageCount : pageRoot + stepageSize;
  •                 pageRoot = pageFoot - stepageSize < pageRoot ? pageFoot - stepageSize : pageRoot;
  •             }
  •            
  •             pagebar = GetDetailbar(stype, stepNum, pageRoot, pageFoot, pageCount, countNum, pageSize, currentPage, Http1, HttpM, HttpN, limitPage);
  •                  
  •             return pagebar;
  •         }
  •         public static string GetPageBar(int mode, string stype, int stepNum, int countNum, int pageSize, int currentPage, string HttpN)
  •         {
  •             return GetPageBar(mode, stype, stepNum, countNum, pageSize, currentPage, HttpN, HttpN, HttpN, 0);
  •         }
  •         public static string GetPageUrl(int chkPage, string Http1, string HttpM, string HttpN, int limitPage)
  •         {
  •             string Http = string.Empty;
  •             if (chkPage == 1)
  •                 Http = Http1;
  •             else
  •                 Http = (chkPage > limitPage || limitPage == 0) ? HttpN : HttpM;
  •             return Http.Replace("<#page#>", chkPage.ToString());
  •         }
  •     }
  • 代碼基本上寫好了,希望對(duì)大家有用,一起學(xué)習(xí),一起進(jìn)步。


    網(wǎng)站欄目:JQuery實(shí)現(xiàn)分頁(yè)程序代碼
    網(wǎng)頁(yè)網(wǎng)址:http://m.5511xx.com/article/dhsdcee.html