0
我有一個分頁功能的gridview,當我想要搜索數據庫中的項目和結果顯示在分頁 GridView中,但是當我跳轉另一頁面gridview將綁定和列出DB中的所有項目與所有頁面,我該如何解決這個問題? 感謝您的意見爲每個結果分頁gridview重新綁定
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();
}