在分页状态下删除纪录的问题
来源:互联网 发布:js怎么给元素改变属性 编辑:程序博客网 时间:2024/05/04 02:57
//检索数据库的函数
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代替
- DataGrid在分页状态下删除纪录的问题
- 在分页状态下删除纪录的问题
- DataGrid在分页状态下删除纪录的问题
- 在分页状态下删除纪录的问题
- DataGrid在分页状态下删除纪录的问题
- 在分页状态下删除纪录的问题
- 在分页状态下删除纪录的问题
- DataGrid在分页状态下删除纪录的问题
- DataGrid在分页状态下删除纪录的问题
- DataGrid常见解决方案:在分页状态下删除纪录的问题
- DataGrid常见解决方案:在分页状态下删除纪录的问题
- 在VBA中删除行纪录代码
- 浅谈在BCB中数组的妙用和纪录和改变控件的状态
- session 在多变量分页下的传递问题
- 在DataSet中实现纪录删除的自定义方法入门7
- Asp.Net在多线程环境下的状态存储问题
- 删除数据中重复的纪录
- GridView和CheckBox结合(在分页状态下)
- FreeTextBox的问题
- 在asp.net中为Web用户控件添加属性和事件
- 巧破IP地址下载限制
- 快快丢掉ASP遗留的各大类陈旧习惯
- datagrid的正反双向排序
- 在分页状态下删除纪录的问题
- 设置墙纸(可用htm,bmp)
- 使用DataGrid动态绑定DropDownList
- 谈JBoss技术架构与服务
- DataGrid删除确认及Item颜色交替
- 下雪了,来武汉三年后的又一场雪。
- KDevelop aclocal.m4:3009 解决办法
- 如何在DataGrid里面产生滚动条而不滚动题头
- MS SQL Server 的安全配置