首页 新闻 会员 周边

关于ASP.NET中的JQ异步获取

0
悬赏园豆:30 [已解决问题] 解决于 2014-03-18 23:48
<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我就不贴出来了,现在我想在这个功能上增加一个根据书名来搜索,应该怎样弄???前后台要怎么写?

banyan.rong的主页 banyan.rong | 初学一级 | 园豆:67
提问于:2014-01-22 14:35
< >
分享
最佳答案
0

查询传参

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"]获取查询数据,去查询

收获园豆:30
骷髅人 | 菜鸟二级 |园豆:464 | 2014-01-24 16:15
其他回答(2)
0

在前后太传输的时候加个参数.前台展示不用变,后台处理的时候根据新加的参数来搜索就行了

吴瑞祥 | 园豆:29449 (高人七级) | 2014-01-22 16:34
0

'BookHandler.ashx?bookName='+书名

wolfy | 园豆:2636 (老鸟四级) | 2014-01-22 17:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册