在jquery price slider事件上调用服务器端方法,它改变了转发器控件的数据源

时间:2012-07-29 20:57:11

标签: c# asp.net jquery controls webmethod

我正在尝试根据用户价格范围选择过滤结果。所以我选择了jquery滑块来显示价格范围。我决定在滑块ajax上使用jquery stop event调用web方法。

在这个阶段,一切都很好。我的网络方法的代码在jquery ajax调用传递的最小和最大范围内过滤记录基础

[WebMethod]
    public static void FilterByPrice(double min,double max)
    {
        List<BALHotelList> searchresult =(List<BALHotelList>) HttpContext.Current.Session["searchresult"];
        searchresult = searchresult.Where(t => (double)t.totalPrice >= min && (double)t.totalPrice <= max).ToList();
        HttpContext.Current.Session["searchresult"] = searchresult;        
        SearchResult s = new SearchResult();
        s.Paging();
    }

现在问题在于Paging方法,该方法用于设置转发器控件的datasource。分页方法如下:

 protected  void Paging()
    {
        List<BALHotelList> searchresult = (List<BALHotelList>)Session["searchresult"];
        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = searchresult;
        objPds.AllowPaging = true;
        objPds.PageSize = Convert.ToInt32(ddlPageNo.SelectedValue);

        objPds.CurrentPageIndex = CurrentPage;

        lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "
           + objPds.PageCount.ToString();

        // Disable Prev or Next buttons if necessary
        cmdPrev.Enabled = !objPds.IsFirstPage;
        cmdNext.Enabled = !objPds.IsLastPage;

        rptHotels.DataSource = objPds;
        rptHotels.DataBind();
    }

当调用此方法时,对象引用未设置的错误。我知道这个页面控件无法访问。当我读到一些完全否定这个issue regarding access page control

的答案时

现在我想知道应该用什么方法来完成我的任务

使用jquery price滑块过滤记录?

1 个答案:

答案 0 :(得分:0)

一种选择是更改 WebMehtod 签名以返回已过滤的记录,并使用jQuery显示它们。这可以通过DataTables jQuery plug-in来完成,This javascript example code是一个用于构建功能丰富的html表的开源工具。

{{3}}展示了如何使用jQuery设置和填充DataTable。