AjaxPro.dll(无刷新分页原理)

源码下载地址:http://download.csdn.net/source/851816 

前台

  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>无刷新分页原型</title>
  6.     <script type="text/javascript">
  7.     function getById(id) 
  8.     { 
  9.         return document.getElementById(id); 
  10.     } 
  11.     function createObj(name) 
  12.     { 
  13.         return document.createElement(name); 
  14.     }
  15.     function showtable(sid)
  16.     { 
  17.         var pager = getById(sid);
  18.         var v = _Default.getDS().value; // 类的名称
  19.         var innerStr = "<table border='1'><tr><td>id</td><td>单位编号</td></tr>";
  20.       
  21.         if (v != null)
  22.         {      
  23.             if(v != null && typeof(v) == "object" && v.Tables != null)
  24.             {           
  25.                 for(var i=0; i<v.Tables[0].Rows.length; i++)
  26.                 {
  27.                     var txt = v.Tables[0].Rows[i].id; //这个地方需要注意区分大小写
  28.                     var vvol = v.Tables[0].Rows[i].num; //跟dataset表的列名称要一致
  29.                     innerStr += "<tr><td>" + txt + "</td>";
  30.                     innerStr += "<td>" + vol + "</td></tr>";
  31.                 }
  32.             }
  33.         }   
  34.         innerStr +="</table>";
  35.         pager.innerHTML=innerStr;
  36.         return;
  37.     }
  38.     document.onclick=function(){
  39.         showtable("pager");
  40.     }
  41.     </script>
  42. </head>
  43. <body>
  44.     <form id="form1" runat="server">
  45.     <div id="pager">
  46.     </div>
  47.     </form>
  48. </body>
  49. </html>
后台
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Data.SqlClient;
  11. public partial class _Default : System.Web.UI.Page 
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.         AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
  16.     }
  17.     /// <summary>
  18.     /// 返回DataSet
  19.     /// </summary>
  20.     /// <returns></returns>
  21.     [AjaxPro.AjaxMethod]
  22.     public DataSet getDS()
  23.     {
  24.         string connStr = ConfigurationManager.ConnectionStrings["hrmbookConnectionString"].ToString();
  25.         SqlConnection conn = new SqlConnection(connStr);
  26.         DataSet ds = new DataSet();
  27.         try
  28.         {
  29.             conn.Open();
  30.             string Sqlstr = "SELECT id,单位编号 num FROM ttest order by 单位编号";
  31.             SqlDataAdapter da = new SqlDataAdapter(Sqlstr, conn);
  32.             da.Fill(ds);
  33.         }
  34.         catch (Exception ex)
  35.         {
  36.             Response.Write(ex.ToString());
  37.         }
  38.         finally
  39.         {
  40.             conn.Close();
  41.         }
  42.         return ds;
  43.     } 
  44. }
配置
  1. <?xml version="1.0"?>
  2. <!-- 
  3.     注意: 除了手动编辑此文件以外,您还可以使用 
  4.     Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
  5.      “网站”->“Asp.Net 配置”选项。
  6.     设置和注释的完整列表在 
  7.     machine.config.comments 中,该文件通常位于 
  8.     /Windows/Microsoft.Net/Framework/v2.x/Config 中
  9. -->
  10. <configuration>
  11.     <appSettings/>
  12.   <connectionStrings>
  13.     <add name="hrmbookConnectionString" connectionString="Data Source=lyylsoft-server,3668;Initial Catalog=hrmbook;Persist Security Info=True;User ID=sa;Password=123"
  14.      providerName="System.Data.SqlClient" />
  15.   </connectionStrings>
  16.     <system.web>
  17.     <!--AjaxPro_Start-->
  18.     <httpHandlers>
  19.       <remove verb="*" path="*.asmx"/>
  20.       <add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
  21.       <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
  22.     </httpHandlers>
  23.     <!--AjaxPro_End-->
  24.         <!-- 
  25.             设置 compilation debug="true" 将调试符号插入
  26.             已编译的页面中。但由于这会 
  27.             影响性能,因此只在开发过程中将此值 
  28.             设置为 true。
  29.         -->
  30.         <compilation debug="true"/>
  31.         <!--
  32.             通过 <authentication> 节可以配置 ASP.NET 使用的 
  33.             安全身份验证模式,
  34.             以标识传入的用户。 
  35.         -->
  36.         <authentication mode="Windows"/>
  37.         <!--
  38.             如果在执行请求的过程中出现未处理的错误,
  39.             则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
  40.             开发人员通过该节可以配置
  41.             要显示的 html 错误页
  42.             以代替错误堆栈跟踪。
  43.         <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
  44.             <error statusCode="403" redirect="NoAccess.htm" />
  45.             <error statusCode="404" redirect="FileNotFound.htm" />
  46.         </customErrors>
  47.         -->
  48.     </system.web>
  49. </configuration>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值