关于gridview 的新手问题 .请高手指教
public void ShowData()
{
objData = new Data();
reader = objData.SelecALlData(); //获取所有的记录
this.gridview1.DataSource = reader;
this.gridview1.DataBind();
}
绑定后不能实现分页了,我如何去实现分页,最好把代码写出来..谢谢大家
[解决办法]
给分吧
1.把gridview的分页属性置位true
2.在gridview的PageIndexChanging中写如下代码:
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.EditIndex = -1;
objData = new Data();
reader = objData.SelecALlData(); //获取所有的记录
this.gridview1.DataSource = reader;
this.gridview1.DataBind();
GridView1.Visible = true;
}
[解决办法]
分页在gridview的OnPageIndexChanging = "page_change "定义
然后在后台:
Sub page_change(ByVal sender As System.Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
bindgridview()
End Sub
就行了
[解决办法]
TO 楼主:你在分页的代码里也要执行一次数据绑定.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.Page = e.NewPageIndex;
ShowData();
}
try~~~