<script type="text/javascript"> $(document).ready(function () { var iBookCount = GetCount();//查找出来的总数量 var pagesParam = { PanelId: 'pages', Count: iBookCount, PageSize: 10, AjaxFn: GetBookList }; var oPages = CreatePagesWidget(pagesParam); GetBookList(1); }); function GetCount() { var iCount = 0; $.ajaxSetup({ async: false }); $.get('BookHandler.ashx', { Type: 'GetCount' }, function (data) { iCount = data; }); return iCount; } function GetBookList(pageIndex) { $.getJSON('BookHandler.ashx', { PageIndex: pageIndex }, function (data) { $("#bookList").empty(); $.each(data, function (index, item) { $("#bookList").append('<li>' + item.BookName + '</li>'); }); }); } </script>
public void ProcessRequest(HttpContext context) { context.Response.Clear(); string sResult = string.Empty; //if (!string.IsNullOrEmpty(context.Request["Type"])) //{ // const string sSql = "select count(*) from bz_Book "; // int iCount = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sSql, null)); // sResult = iCount.ToString(); //} if (!string.IsNullOrEmpty(context.Request["PageIndex"])) { int iPageIndex = int.Parse(context.Request["PageIndex"]); PageListInfo pli = new PageListInfo(); pli.tblName = "bz_Book";// 表名 pli.fldName = @"Book_Name";// 字段列表 pli.fldSort = "Book_Id";// 排序字段 pli.KeyID = "Book_Id"; pli.Sort = true;// 排序方法,0为升序,1为降序 pli.strWhere = string.Empty;// 查询条件 pli.currentPageIndex = iPageIndex;// 当前页码 pli.PageSize = 10;// 每页记录数 PageListInfo plii = PageListBLL.GetPageList(pli); JavaScriptSerializer json = new JavaScriptSerializer(); IList<Dictionary<string, string>> items = new List<Dictionary<string, string>>(); foreach (DataRow dr in plii.ReturnTable.Rows) { Dictionary<string, string> item = new Dictionary<string, string>(); item.Add("BookName", dr["Book_Name"].ToString()); item.Add("BookAuthor", dr["Book_Author"].ToString()); items.Add(item); } sResult = json.Serialize(items); } context.Response.Write(sResult); context.Response.End(); } public bool IsReusable { get { return false; } } }
还有就是模仿AspPageNet控件 的分页事件的JS我就不贴出来了,现在我想在这个功能上增加一个根据书名来搜索,应该怎样弄???前后台要怎么写?
查询传参
function GetBookList(pageIndex) {
$.getJSON('BookHandler.ashx', {PageIndex: pageIndex ,BookName:book_name}, function (data) {
$("#bookList").empty(); $.each(data, function (index, item) {
$("#bookList").append('<li>' + item.BookName + '</li>'); });
});
统计页数也要传
function GetCount() {
var iCount = 0; $.ajaxSetup({ async: false });
$.get('BookHandler.ashx', { Type: 'GetCount',BookName:book_name }, function (data) {
iCount = data;
});
return iCount;
}
后台context.Request["BookName"]获取查询数据,去查询
在前后太传输的时候加个参数.前台展示不用变,后台处理的时候根据新加的参数来搜索就行了
'BookHandler.ashx?bookName='+书名