If d1.CurrentPageIndex < 0 Then d1.CurrentPageIndex = 0 Else If d1.CurrentPageIndex > d1.PageCount Then d1.CurrentPageIndex = d1.PageCount Else d1.CurrentPageIndex = e.NewPageIndex End If End If d1.databind d1为datagrid,我用的是vb,你转换为c#即可,看看结果如何,应该是你加了 限制条件以后,在改变条件时出来错误了
int indexsum; indexsum=dataplan.CurrentPageIndex; dataplan.CurrentPageIndex=0; dataplan.DataBind(); dataplan.CurrentPageIndex=indexsum; if (indexsum>dataplan.PageCount-1) { dataplan.CurrentPageIndex--; dataplan.DataBind(); } else { dataplan.DataBind(); } 需要DataBind()两次
lulu_zz(luluer),luofix(枯古)二位兄台:我已如老兄所说绑定,依然无效。 5555555555555555555555555555 求助中。 小弟这厢有礼。 lulu_zz(luluer) ://换页 if (DataGrid1.CurrentPageIndex< 0) DataGrid1.CurrentPageIndex=0; else if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1) DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1; else DataGrid1.CurrentPageIndex=e.NewPageIndex; DataGrid1.DataBind(); luofix(枯古): DataGrid1.CurrentPageIndex=0; DataGrid1.DataBind();
if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1) { DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1; DataGrid1.DataBind(); } DataGrid1.CurrentPageIndex=e.NewPageIndex; DataGrid1.DataBind();
多谢!
小弟这厢有礼.
{ DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindData();//重新绑定
}
解决的办法是:DataGrid1.CurrentPageIndex = 0
首先设定datagrid1的页数为第一页,但是你要注意,翻页的时候,不能执行这个语句,只有在重新执行查询的时候才执行。
然后在page_load和datagrid1_pageindexchanaged()事件中调用。
chenbinghui(阿炳):
两位仁兄,小弟先行谢过。在断点跟踪时发现:
DataGrid1.CurrentPageIndex=e.NewPageIndex;
之前,DataGrid1.CurrentPageIndex已经为零,我尝试在查询时将
DataGrid1.CurrentPageIndex=0;无效!spring_ok(SpringDotNet):
我尝试写过自己定义的函数以实现数据绑定,使用系统自已生成的:protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbCommand1;
protected BGWeb.DataSet1 dataSet12;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
依然出错。我当如何?
求救中。 小弟这厢有礼
请稍后,容我再试一下。
多谢关照。
小弟这厢有礼!
void ChangePage(Object sender, DataGridPageChangedEventArgs e)
{
startIndex = e.NewPageIndex*Grid1.PageSize;
Grid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
闻道有先后,术业有专攻,程序员当互相学习,以助人为己乐,岂是嘲弄他人而后快? 请老兄赐教:
1、DataGrid查询、排序后可实现正常分页?
2、如何使用:
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbCommand1;
protected BGWeb.DataSet1 dataSet12;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
(系统自定义) 实现数据绑定。
3、不自已书写数据绑定函数,只使用
DataGrid.DataBind();可以吗达到我的要求吗。
虚心请教。 小弟这厢有礼
d1.CurrentPageIndex = 0
Else
If d1.CurrentPageIndex > d1.PageCount Then
d1.CurrentPageIndex = d1.PageCount
Else
d1.CurrentPageIndex = e.NewPageIndex
End If
End If
d1.databind
d1为datagrid,我用的是vb,你转换为c#即可,看看结果如何,应该是你加了
限制条件以后,在改变条件时出来错误了
indexsum=dataplan.CurrentPageIndex;
dataplan.CurrentPageIndex=0;
dataplan.DataBind();
dataplan.CurrentPageIndex=indexsum;
if (indexsum>dataplan.PageCount-1)
{
dataplan.CurrentPageIndex--;
dataplan.DataBind();
}
else
{
dataplan.DataBind();
}
需要DataBind()两次
5555555555555555555555555555
求助中。
小弟这厢有礼。
lulu_zz(luluer) ://换页
if (DataGrid1.CurrentPageIndex< 0)
DataGrid1.CurrentPageIndex=0;
else
if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1)
DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1;
else
DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataGrid1.DataBind();
luofix(枯古):
DataGrid1.CurrentPageIndex=0;
DataGrid1.DataBind();
if (DataGrid1.CurrentPageIndex>DataGrid1.PageCount-1)
{
DataGrid1.CurrentPageIndex=DataGrid1.PageCount-1;
DataGrid1.DataBind();
} DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataGrid1.DataBind();
什么风格不风格,
程序员就是解决问题,问题解决了就好,
我真看不惯你这样的!
Grid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();