上一篇:datagrid的正反双向排序 >>
DataGrid在分页状态下删除纪录的问题
//检索数据库的函数
public DataSet GetZcbd()
{
try
{
DataSet ds=new DataSet();
string searchString="select id,yy,bj from zc";
da=new OleDbDataAdapter(searchString,conn);
da.Fill(ds,"yy");
return ds;
}
catch
{
return null;
}
}
//绑定DataGrid
private void BindGrid()
{
DataSet ds = new DataSet();
ds = us.GetZcbd();
if (ds!=null)
{
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
}
else
{
msg.Alert("加载数据错误!",Page);
}
}
//删除数据库纪录函数
public string DeleteZcbd(int bdID)
{
int count = this.IfExiseZysx(bdID);//不必理会次句,默认count=1
if (count <= 0) return "false";
else
{
string sqlStr = "delete from zcwhere id="+bdID;
OleDbCommand cmd = new OleDbCommand(sqlStr,conn);
conn.Open();
try
{
cmd.ExecuteNonQuery();
return "true";
}
catch(Exception e)
{
return e.Message.ToString();
}
finally
{
conn.Close();
}
}
}
// DataGrid1_DeleteCommand事件修改函数
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int bdID = int.Parse(DataGrid1.DataKeys[(int)e.Item.ItemIndex].ToString());
string isDel = us.DeleteZcbd(bdID);
int CurrentPage = 0;
if (isDel == "true")
{
if(this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount -1)
{
if (this.DataGrid1.CurrentPageIndex == 0)
{
this.DataGrid1.CurrentPageIndex = this.DataGrid1.PageCount -1;
}
else
{
if (this.DataGrid1.Items.Count % this.DataGrid1.PageSize == 1)
{
CurrentPage = 2;
}
else
{
CurrentPage = 1;
}
this.DataGrid1.CurrentPageIndex = this.DataGrid1.PageCount - CurrentPage;
}
}
this.BindGrid();
}
else
{
msg.Alert("删除数据错误!",Page);
}
}
注释:msg为一个类似WinForm的messagebox对话框,不必理会。可以使用label.Text代替
代码很乱,敬请谅解!
下一篇:未找到路径“D:\”的一部分 的问题解决 >>
相关文章:
- · 程序员的.NET时代(二)
- · 程序员的.NET时代(一)
- · 品味.NET巨著——书评《Microsoft .NET框架程序设计(修订版)》
- · 解决.NET(WebApplication)安装部署的不能选择安装路径的问题
- · Beta 1 到 Beta 2 改变详细列表(英文)Beta 1 to Beta 2 Changes
- · Microsoft Visual J#.NET (JSharp) Version 7.0 Beta 1 out
- · Microsoft Visual Studio.NET及Borland Delphi6初探
- · .NET对软件安装的冲击
- · Microsoft Tech Ed
- · .NET 和 COM 之间的相互访问
- · 介绍.NET中的委派(一)
- · .NET架构的核心开发技术
- · 控制VC++.NET中WEB对话框的HTML元素属性
- · Borland Eyeing the Chasm Between Java and .NET
- · .Net 是未来的趋势, 为什么?
- · Microsoft .NET Development Platform的Linux版本(Mono)出现
- · 价值上千美元的Visual Studio.NET β2的培训
- · 使用 Microsoft.NET Frameworks 创建Windows应用程序
- · DataGrid连接Access的快速分页法(1)——需求与现状
- · 用Socket类构建网页下载器
- · COM与.NET的互操作(初级)
- · .NET 的对象关系持久化机制(1)
- · Websharp使用说明(8)
- · Websharp使用说明(7)
- · Websharp使用说明(6)
- · Websharp使用说明(5)
- · Websharp使用说明(4)
- · Websharp使用说明(3)
- · Websharp使用说明(2)
- · Websharp使用说明(1)
- · 使.NET命名空间符合标准
- · Repeater控件的分页问题
- · 用.Net构架你的系统(基类的搭建思路)
- · .NET断想
- · 常见 Datagrid 错误
- · .NET 数据访问架构指南(二)
- · .NET 数据访问架构指南(一)
- · 开发合作 Microsoft .NET 解决方案
