简体   繁体   English

为搜索结果重新绑定时的asp.net gridview分页问题

[英]asp.net gridview paging issue when rebinding it for a search result

I have a grid view and I bind it on first page load , I have some searching optionst on the same page , when search button is clicked I query the seaarch and i rebind the gridview with the new datasource comming out of search result , the problem is after rebinding the gridview I have paging problems which I don't have them in the first pageload data binding ! 我有一个网格视图,并在第一页加载时绑定了它,在同一页面上有一些搜索选项,单击搜索按钮时,我查询了seaarch,然后将网格视图与新的数据源重新绑定,这个新的数据源来自搜索结果,这个问题重新绑定gridview之后,我遇到了分页问题,​​在第一个页面加载数据绑定中我没有这些问题! could anyone tell me why is that ?! 谁能告诉我为什么?

Here is my Page_Load coe : 这是我的Page_Load coe:

protected void Page_Load(object sender, EventArgs e)
{
    DisableChaching();
    string val = Convert.ToString(Session["AccessLevel"]);
    if (Request.Cookies["UserName"] == null)
    {
        if (Session["UserName"] == null)
        {
            Response.Redirect("~/Default.aspx");
        }
        else if (val   == "2")
        {
            Response.Redirect("~/Default.aspx");
        }
    }
    else if (val == "2")
    {
        Response.Redirect("~/Default.aspx");
    }
    if (!IsPostBack)
    {
        LoadControls();
        BindGrid();
    }
}

My GV_PageIndexChanging : 我的GV_PageIndexChanging:

protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

    GV.PageIndex = e.NewPageIndex;
    BindGrid();
    PageStatus(Status.None);
}

my btnSearch_Click : 我的btnSearch_Click:

 protected void btnSearch_Click(object sender, ImageClickEventArgs e)
 {
query = new CommonQueries();
       GV.DataSource = query.getBooksByGroupIDSubGroupID(DrpGroup.SelectedItem.Value,DrpSubGroup.SelectedItem.Value);
     GV.DataBind();
 }

And in CommonQueries Class I have this query wich I used befor : 在CommonQueries类中,我使用befor进行了以下查询:

    public List<Book> getBooksByGroupIDSubGroupID(string GroupID, string SubGroupID)
{
    db = new BookMarketDataContext();
    List<Book> list = new List<Book>();
    list = (from b in db.Books where b.GroupID.ToString() == GroupID && b.SubGroupID.ToString() == SubGroupID  orderby b.Name select b).ToList();
    return list;
}

TO BE MORE SPECIFIC : On my Page loads I don't have any problem with gridview page changing BUT after clicking the search button "btnSearch" and rebinding the gridview , if search results are enough to cause the gridview to have pagenumbers , and when I click one of those page numbers I get wrong results from the previous page_Load ! 更具体:在我的页面加载中,如果搜索结果足以导致gridview具有页码,并且当我单击搜索按钮“ btnSearch”并重新绑定gridview之后,更改gridview页面没有任何问题,但是单击这些页码之一,我从上一页page_Load中得到错误结果!

It appears that your postback on paging doesn't include information on which viewstate it should be paging. 看来您的分页回发不包含有关应将其分页的视图状态的信息。 You should be pushing that information down to the page so that it can be included in the postback, or storing it in user session (less roundtrip, more weight on the server, but faster responses if you're also storing the query result)... 您应该将该信息下推至页面,以便可以将其包含在回发中,或将其存储在用户会话中(往返次数更少,服务器上的权重更大,但是如果您还存储查询结果,则响应速度更快)。 ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM