/**************************
创建XMLHttpRequest对象
**************************/
function CreateRequest()
{
var xmlObj = null;
try
{
xmlObj = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlObj = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e2)
{
try
{
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e3)
{
xmlObj = null;
}
}
}
if ( !xmlObj && typeof XMLHttpRequest != "undefined" )
{
xmlObj=new XMLHttpRequest();
}
return xmlObj;
}
**************************/
function CreateRequest()
{
var xmlObj = null;
try
{
xmlObj = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlObj = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e2)
{
try
{
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e3)
{
xmlObj = null;
}
}
}
if ( !xmlObj && typeof XMLHttpRequest != "undefined" )
{
xmlObj=new XMLHttpRequest();
}
return xmlObj;
}
function
Poress(weburl,objID)
{
var objP = document.getElementById(objID) //得到父控件
xmlhttp CreateRequest(); 初始化个xmlhttp对象 xmlhttp.open("get,weburl,true); 提交数据 xmlhttp.onreadystatechangefunction()
...{
if(xmlhttp.readyState==4)4代表成功返回数据
...{
result xmlhttp.responseText;得到服务器返回的数据 (result.indexOf(##Err##>=0)
...{
pageresult.substr());
regExp=/page([-9]*/i;
weburlchkUrl(weburl,regExp,0);">page=+page);
Poress(weburl,objID);
}
else
objP.innerHTMLresult;
}
};
xmlhttp.send(null发送数据,请注意顺序和参数,参数一定为null或者""
}
changeUrl(weburl,divID)
... txtPagedocument.getElementById(txtPage);
(txtPage!=)
...{
pagetxtPage.value;
i;
weburlpage);
}
(divID.length)
location.hrefweburl;
Process(weburl,divID);
}
changePage(page)
... );
txtPage.valuepage;
} chkUrl(url,parma)
... (url.indexOf(?<)
url+=parma;
(regExp.test(url))
...{
urlurl.replace(regExp,parma);
}
url&return url;
} changeOrderUrl(weburl,divID,ascValue)
... drpSortBydrpSortBy btnOrderbtnOrder);
SortBy^&i;
weburlSortBy=drpSortBy.value);
(btnOrder.valueascValue)
strSortOrderDESC
strSortOrderASC
regExpSortOrderSortOrder=strSortOrder);
changeOrder()
... );
btnOrder.value'';
}
{
var objP = document.getElementById(objID) //得到父控件
xmlhttp CreateRequest(); 初始化个xmlhttp对象 xmlhttp.open("get,weburl,true); 提交数据 xmlhttp.onreadystatechangefunction()
...{
if(xmlhttp.readyState==4)4代表成功返回数据
...{
result xmlhttp.responseText;得到服务器返回的数据 (result.indexOf(##Err##>=0)
...{
pageresult.substr());
regExp=/page([-9]*/i;
weburlchkUrl(weburl,regExp,0);">page=+page);
Poress(weburl,objID);
}
else
objP.innerHTMLresult;
}
};
xmlhttp.send(null发送数据,请注意顺序和参数,参数一定为null或者""
}
changeUrl(weburl,divID)
... txtPagedocument.getElementById(txtPage);
(txtPage!=)
...{
pagetxtPage.value;
i;
weburlpage);
}
(divID.length)
location.hrefweburl;
Process(weburl,divID);
}
changePage(page)
... );
txtPage.valuepage;
} chkUrl(url,parma)
... (url.indexOf(?<)
url+=parma;
(regExp.test(url))
...{
urlurl.replace(regExp,parma);
}
url&return url;
} changeOrderUrl(weburl,divID,ascValue)
... drpSortBydrpSortBy btnOrderbtnOrder);
SortBy^&i;
weburlSortBy=drpSortBy.value);
(btnOrder.valueascValue)
strSortOrderDESC
strSortOrderASC
regExpSortOrderSortOrder=strSortOrder);
changeOrder()
... );
btnOrder.value'';
}
ascx
请自己设置载入JS文件
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PageControl.ascx.cs" Inherits="DonDear.Web.UserControls.PageControl" %>
<asp:Literal ID="ltPage" runat="server"></asp:Literal>
<asp:Literal ID="ltPage" runat="server"></asp:Literal>
cs
using
System;
System.Data;
System.Configuration;
System.Collections;
System.Text.RegularExpressions;
System.Text;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Web.UI.HtmlControls;
DonDear.Utility;
namespace DonDear.Web.UserControls
... publicpartialclass PageControl : System.Web.UI.UserControl
...string mStyleClass ""首页尾页上页下页Go;
int mPage 201215bool mShowButton false mContentID ;
ContentID
...{
set ...{ this.mContentID value; }
}
StyleClass
...{
....mStyleClass SelectedStyleClass
...{
....mSelectedStyleClass
InputStyle
...{
....mInputStyle ButtonStyle
...{
....mButtonStyle FirstPage
...{
....mFirstPage LastPage
...{
....mLastPage PrePage
...{
....mPrePage NextPage
...{
....mNextPage GoPage
...{
....mGoPage ToPage
...{
....mPage
get....mPage; } PageSize
...{
....mPageSize
....mPageSize; } TotalCount
...{
....mTotalCount; }
....mTotalCount ShowCount
...{
....mShowCount ShowButton
...{
....mShowButton ShowFix
...{
....mShowFix protectedvoid Page_Load(object sender, EventArgs e)
...{
webUrl .Request.Url.ToString();
Regex regExp new Regex(Page=([-0-9]*) (!Page.IsPostBack)
...{
pageCount 1;
>)
...{
((mTotalCount % mPageSize) )
pageCount mTotalCount mPageSize;
pageCount (mTotalCount ;
}
StringBuilder sb StringBuilder();
(Request.QueryString[Page] &&.mPage)
Convert.ToInt32(Request.QueryString[]);
)
...;
webUrl StrHelper.ReplaceUrl(webUrl, regExp, Page=1);
Response.Redirect(webUrl);
}
pageCount)
... pageCount;
webUrl Page= pageCount.ToString());
Response.Redirect(webUrl);
}
... strScript javascript:changeUrl('','');;
strClick <=)
sb.Append(<a mFirstPage </a> <a mPrePage </a> );
...{
strClick changePage(1); strScript;
sb.Append(<a href='javascript:;' οnclick="" );
strClick changePage() ););
}
befPageCount 2 pageCount;
pageCount)
(()
midPage
midPage ;
befPageCount midPage ;
nextPageCount midPage;
}
midPage)
...{
fromPage midPage);
toPage midPage;
}
toPage .mShowCount;
midPage) pageCount)
...;
toPage pageCount;
}
(fromPage .mShowFix)
sb.Append(>...</a> );
for i fromPage; i toPage; i++)
...{
(i .mPage)
sb.Append();
...{
strClick strScript;
sb.Append();
}
} (toPage pageCount)
sb.Append(
... mNextPage mLastPage strStyle .mShowButton)
...{
strStyle display:none;;
}
sb.Append(<input size='3px' type='text' id='txtPage' value='' mInputStyle style='width: 23px;'> <input type='button' id='btnGo' οnclick=" mButtonStyle value=' mGoPage ' style='' /> );
}.ltPage.Text sb.ToString();
}
}
System.Data;
System.Configuration;
System.Collections;
System.Text.RegularExpressions;
System.Text;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Web.UI.HtmlControls;
DonDear.Utility;
namespace DonDear.Web.UserControls
... publicpartialclass PageControl : System.Web.UI.UserControl
...string mStyleClass ""首页尾页上页下页Go;
int mPage 201215bool mShowButton false mContentID ;
ContentID
...{
set ...{ this.mContentID value; }
}
StyleClass
...{
....mStyleClass SelectedStyleClass
...{
....mSelectedStyleClass
InputStyle
...{
....mInputStyle ButtonStyle
...{
....mButtonStyle FirstPage
...{
....mFirstPage LastPage
...{
....mLastPage PrePage
...{
....mPrePage NextPage
...{
....mNextPage GoPage
...{
....mGoPage ToPage
...{
....mPage
get....mPage; } PageSize
...{
....mPageSize
....mPageSize; } TotalCount
...{
....mTotalCount; }
....mTotalCount ShowCount
...{
....mShowCount ShowButton
...{
....mShowButton ShowFix
...{
....mShowFix protectedvoid Page_Load(object sender, EventArgs e)
...{
webUrl .Request.Url.ToString();
Regex regExp new Regex(Page=([-0-9]*) (!Page.IsPostBack)
...{
pageCount 1;
>)
...{
((mTotalCount % mPageSize) )
pageCount mTotalCount mPageSize;
pageCount (mTotalCount ;
}
StringBuilder sb StringBuilder();
(Request.QueryString[Page] &&.mPage)
Convert.ToInt32(Request.QueryString[]);
)
...;
webUrl StrHelper.ReplaceUrl(webUrl, regExp, Page=1);
Response.Redirect(webUrl);
}
pageCount)
... pageCount;
webUrl Page= pageCount.ToString());
Response.Redirect(webUrl);
}
... strScript javascript:changeUrl('','');;
strClick <=)
sb.Append(<a mFirstPage </a> <a mPrePage </a> );
...{
strClick changePage(1); strScript;
sb.Append(<a href='javascript:;' οnclick="" );
strClick changePage() ););
}
befPageCount 2 pageCount;
pageCount)
(()
midPage
midPage ;
befPageCount midPage ;
nextPageCount midPage;
}
midPage)
...{
fromPage midPage);
toPage midPage;
}
toPage .mShowCount;
midPage) pageCount)
...;
toPage pageCount;
}
(fromPage .mShowFix)
sb.Append(>...</a> );
for i fromPage; i toPage; i++)
...{
(i .mPage)
sb.Append();
...{
strClick strScript;
sb.Append();
}
} (toPage pageCount)
sb.Append(
... mNextPage mLastPage strStyle .mShowButton)
...{
strStyle display:none;;
}
sb.Append(<input size='3px' type='text' id='txtPage' value='' mInputStyle style='width: 23px;'> <input type='button' id='btnGo' οnclick=" mButtonStyle value=' mGoPage ' style='' /> );
}.ltPage.Text sb.ToString();
}
}
原文地址:https://blog.csdn.net/lee576/article/details/2040092
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。