我的GridView
填充了某个过滤条件。
我有PageIndexChanging
个事件来执行我的数据分页。
protected void gvPeople_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
lblAddError.Text = String.Empty;
List<People> list = (List<People>)ViewState[_vsPeopleList];
gvPeople.DataSource = list;
gvPeople.PageIndex = e.NewPageIndex;
gvPeople.EditIndex = -1;
gvPeople.DataBind();
}
之后,我在不更改过滤条件的情况下执行Search
。
protected void btnPeopleSearch_Click(object sender, CommandEventArgs e)
{
if(e.CommandName.Equals("Search"))
{
PopulatePeople();
}
}
private void PopulatePeople()
{
lblAddError.Text = String.Empty;
if (ViewState["_message"] != null)
{
lblAddError.Visible = true;
lblAddError.Text = ViewState["_message"].ToString();
}
ViewState["_message"] = null;
int portfolio = int.Parse(ddlPortfolio.SelectedItem.Value);
ViewState["portfolioID"] = portfolio;
string year = ddlYear.SelectedItem.Text;
string month = ddlMonth.SelectedItem.Text;
List<People> list = People.GetPeople(portfolio, year, month);
ViewState[_vsPeopleList] = list;
if(list.Count == 0)
{
gvPeople.Visible = false;
lblAddError.Visible = true;
lblAddError.Text = "No data available for current selection";
}
else
{
gvPeople.Visible = true;
gvPeople.DataSource = list;
gvPeople.DataBind();
}
}
我应该像在分页到下一页之前那样获得GridView
中的所有数据。但是,我的页面不会刷新以显示所有数据,它只显示该页面索引的数据,但是,我的列表计数等于从数据库填充的记录数。此外,如果我更改搜索过滤器,则会正确显示数据。
我做错了什么?
答案 0 :(得分:0)
看起来gvHolidays_PageIndexChanging事件与其他网格相关,因为其中编写的代码适用于网格gvPeople。
如果没有,请尝试以下操作。
//Write the following code inside gridviews PageIndexChanging event.
gvPeople.PageIndex = e.NewPageIndex;
gvPeople.EditIndex = -1;
gvPeople.SelectedIndex = -1;
//Write the following code inside gvHolidays_PageIndexChanged event.
lblAddError.Text = String.Empty;
List<People> list = (List<People>)ViewState[_vsPeopleList];
gvPeople.DataSource = list;
gvPeople.DataBind();