<script type="text/javascript"> </script> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="NoFlush.aspx.cs" Inherits="NoFlush" %> <%@ OutputCache Duration="30" VaryByControl="any" %> <!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 runat="server"> <title>无标题页</title> <mce:script language="javascript"><!-- var xmlHttp; var currPage=1; var totalPage; var totalCount; function creatXMLHttp(){ if(window.ActiveXObject){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); } } function requset(type){ if(type=="Head"){ currPage=1; }else if(type=="Previous"){ if(currPage<=1) currPage=1; else currPage--; }else if(type=="Next"){ if(currPage>=totalPage) currPage=totalPage; else currPage++; }else if(type=="Last"){ currPage=totalPage; } creatXMLHttp(); xmlHttp.open("get","NoFlushAdmin.aspx?currPage="+currPage,true); xmlHttp.onreadystatechange=callBack; xmlHttp.send(null); } function callBack(){ if(xmlHttp.readyState==4){ if(xmlHttp.status==200){ show(); } } } function show(){ var xmldoc = xmlHttp.responseXML.documentElement.childNodes[0]; var div=document.getElementById("show"); var str="<table><tr><td>编号</td><td>姓名</td><td>年龄</td></tr>"; for(var i=0;i<xmldoc.childNodes.length;i++){ str+="<tr><td>"+xmldoc.childNodes[i].childNodes[0].nodeTypedValue+"</td>"; str+="<td>"+xmldoc.childNodes[i].childNodes[1].nodeTypedValue+"</td>"; str+="<td>"+xmldoc.childNodes[i].childNodes[2].nodeTypedValue+"</td></tr>"; } str+="</table>"; div.innerHTML=str; totalPage=xmlHttp.responseXML.getElementsByTagName("totalPage")[0].nodeTypedValue; totalCount=xmlHttp.responseXML.getElementsByTagName("totalCount")[0].nodeTypedValue; document.getElementById("show3").innerHTML=currPage+"/"+totalPage+" 总共有<b>"+totalCount+"</b>条记录"; } window.οnlοad=function(){ requset("Head"); } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div id="show"> </div> <div id="show1"> <input type="button" value="首页" οnclick="requset('Head')" /> <input id="Button1" type="button" value="上一页" οnclick="requset('Previous')" /> <input id="Button2" type="button" value="下一页" οnclick="requset('Next')" /> <input id="Button3" type="button" value="尾页" οnclick="requset('Last')" /> <div id="show3"> </div> </div> </form> </body> </html> using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; public partial class NoFlushAdmin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int currPage = Convert.ToInt32(Request.QueryString["currPage"]) == 0 ? 1 : Convert.ToInt32(Request.QueryString["currPage"]); string sql = "select top 10 * from [User] where [id] not in (select top " + 10 * (currPage - 1) + " [id] from [User])"; System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(sql, "Data Source=.;Initial Catalog=Test;Integrated Security=True"); DataSet ds = new DataSet(); da.Fill(ds); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<Users><infor>"); foreach (DataRow dr in ds.Tables[0].Rows) { sb.Append("<user>"); sb.Append("<id>").Append(dr["id"]).Append("</id>"); sb.Append("<name>").Append(dr["name"]).Append("</name>"); sb.Append("<age>").Append(dr["age"]).Append("</age>"); sb.Append("</user>"); } System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select count(*) from [User]", new System.Data.SqlClient.SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True")); cmd.Connection.Open(); int totalCount = (int)cmd.ExecuteScalar(); int totalPage = ((int)cmd.ExecuteScalar()) % 10 == 0 ? ((int)cmd.ExecuteScalar()) / 10 : ((int)cmd.ExecuteScalar()) / 10 + 1; cmd.Connection.Close(); sb.Append("</infor><totalPage>" + totalPage + "</totalPage>"); sb.Append("<totalCount>" + totalCount + "</totalCount>"); sb.Append("</Users>"); Response.AddHeader("Chache-control", "nocache"); Response.ContentType = "text/xml"; Response.Write(sb.ToString()); Response.End(); } }