我有一个gridview,我用它来显示数据集结果。 问题是我在其中使用分页。但是,当我点击页面#时,它表示我没有处理该事件。我需要重新绑定数据集???
由于
答案 0 :(得分:31)
请尝试以下代码:
protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
FillGrid();
grdView.PageIndex = e.NewPageIndex;
grdView.DataBind();
}
答案 1 :(得分:4)
试试吧
在页面加载
中protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
loadGrid();
}
}
在pageindexchanging
中private void loadGrid()
{
using (your_bankEntities context = new your_bankEntities()) //use your connection .edmx
{
var jmDados = (from jm in context.yourdbo orderby jm.your fieldkey
select new
{
jm.Field1,
jm.Field2,
jm.Field3,
jm.Field4,
........
jm.n
}).ToList();
GridView1.DataSource = jmDados;
GridView1.DataBind();
}
}
在pageindexchanging
中GridView1.PageIndex = e.NewPageIndex;
loadGrid();
答案 2 :(得分:1)
在VB.net中,它与C#没有太大区别,你只需删除每一行末尾的分号
Private Sub myGridview_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles myGridview.PageIndexChanging
LoadGridView() //Call your method to load the data into the grid.
myGridview.PageIndex = e.NewPageIndex
myGridview.DataBind()
End Sub
答案 3 :(得分:0)
您应该在绑定数据之前设置.PageIndex!否则,您将需要额外的点击,它们实际上会加倍调用BindData方法。以下是我经过测试的vb代码。
Private Sub GridViewL_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridViewL.PageIndexChanging
GridViewL.PageIndex = e.NewPageIndex
BindData() ' your method to bind data to the grid
End Sub