具有分页功能的DataGrid,如果有删除功能,可能回发生错误
2006-12-20 14:16
459 查看
具有分页功能的DataGrid,如果有删除功能,则在删除最后一页的最后一项的时候,会出现错误,提示错误:无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。解决方案如下:
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = e.Item.Cells[1].Text;
Cn.Edu.Hbsi.Data.Database db = new Cn.Edu.Hbsi.Data.Database("Server=.;database=webshoppe;uid=sa",Cn.Edu.Hbsi.Data.DBType.SqlServer);
db.ExecuteCommand("delete from authors where aid='" + id + "'");
if(this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount -1) //最后一页
{
if(this.DataGrid1.Items.Count == 1) //当前删除的是最后一行
{
if(this.DataGrid1.CurrentPageIndex >= 1)
this.DataGrid1.CurrentPageIndex--;
}
}
this.bind(); //重新绑定数据
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = e.Item.Cells[1].Text;
Cn.Edu.Hbsi.Data.Database db = new Cn.Edu.Hbsi.Data.Database("Server=.;database=webshoppe;uid=sa",Cn.Edu.Hbsi.Data.DBType.SqlServer);
db.ExecuteCommand("delete from authors where aid='" + id + "'");
if(this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount -1) //最后一页
{
if(this.DataGrid1.Items.Count == 1) //当前删除的是最后一行
{
if(this.DataGrid1.CurrentPageIndex >= 1)
this.DataGrid1.CurrentPageIndex--;
}
}
this.bind(); //重新绑定数据
}
相关文章推荐
- DataGrid删除数据的时候避免错误发生
- DataGrid同时具有分页和排序功能及注意点
- 删除具有分页的DataGrid,当前页不为0且当前页的记录只有一条的时候的解决方案
- datagrid分页中如果删除时出现超出索引
- EF(Entity Framework)发生错误”正在创建模型,此时不可使用上下文“的解决办法。 正在创建模型,此时不可使用上下文。如果在 OnModelCreating 方法内使用上下文或如果多个线程同时访问同一上下文实例,可能引发此异常。请注意不保证 DbContext 的实例成员和相关类是线程安全的。 临时解决了这个问题,在Context的构造函数中,禁用了自动初始化:
- DataGrid有分页时的删除错误
- DataGrid同时具有分页和排序功能及注意点
- DataGrid带分页功能时更新.删除操作
- DataGrid同时具有分页和排序功能及注意点
- datagrid分页中如果删除时出现超出索引收藏
- DataGrid有分页时的删除错误
- JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能
- DataGrid带分页功能时更新.删除操作
- C#中DataGrid分页,修改,更新,删除功能的实现
- 关于Entity Framework更新的几种方式以及可能遇到的问题(附加类型“Model”的实体失败,因为相同类型的其他实体已具有相同的主键值)在使用 "Attach" 方法或者将实体的状态设置为 "Unchanged" 或 "Modified" 时如果图形中的任何实体具有冲突键值,则可能会发生上述行为
- 实例:SSH结合Easyui实现Datagrid的批量删除功能
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。
- 问题:DataGrid该行并不总是很清楚验证错误(删除), 解决方案,如下面
- 如何在DataGrid中实现分页功能
- 一个功能齐全的DataGrid分页例子