我有一个带有分页功能的 gridview,当我想在 DB 中搜索项目并在 gridview 中显示分页结果时,但是当我跳转另一个页面时,gridview 将绑定并列出所有页面的 DB 中的所有项目,我该如何解决这个问题?谢谢你的建议
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
private void BindGridView()
{
using (NoavaranModel.NoavaranEntities1 dbContext = new NoavaranModel.NoavaranEntities1())
{
var query = from list in dbContext.Students
select list;
lblStudentsCount.Text = query.Count().ToString();
GridView1.DataSource = query;
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridView();
GridView1.DataBind();
}