您的位置:首页 > 其它

具有分页功能的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(); //重新绑定数据
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐