我用下面的方法实现了,可是我要计算一共删除了多少条数据,要如何弄呢,也就是说前面选择了几条数据
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1"); if (cb.Checked)
{
string delnum = GridView1.Rows.Count.ToString();
int strid = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
Label1.Text = strid.ToString();
SqlConnection con = db.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from cwissrec where Recid=" + strid + "", con);
cmd.ExecuteReader();
Response.Write("<script>alert('成功删除" + delnum + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");
}
else
{
Response.Write("<script>alert('您没有选择要删除的项目')</script>");
}
}
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1"); if (cb.Checked)
{
string delnum = GridView1.Rows.Count.ToString();
int strid = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
Label1.Text = strid.ToString();
SqlConnection con = db.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from cwissrec where Recid=" + strid + "", con);
cmd.ExecuteReader();
Response.Write("<script>alert('成功删除" + delnum + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");
}
else
{
Response.Write("<script>alert('您没有选择要删除的项目')</script>");
}
}
解决方案 »
- ASCX做的head,footer控件在每个页面都要引用吗?有没有什么简单的方法?
- 请教有关asp.net中变量值保持的问题
- 获取服务器时间(存储过程)
- 如何把设计好的网页图片切成HTML的呢?
- 如何在.aspx.cs中得到DataGrid中的一条记录的某个字段的值??????急,等!
- 简单的update 语句的疑惑,请帮忙
- 疑惑:各位大哥的项目中用上了类工厂、接口类吗?您认为何种情况下才需要用?谢谢!!!
- 求 只能输入 数字和分号(“;”)的正则表达式。
- 各位哥哥姐姐,帮我看一下把,我的这么简单的程序怎么不对啊?----我是初学者
- 请问怎么远程管理sql server 2000数据库?
- 如何将.cs文件和aspx(界面关联起来),我想用.cs类文件对,界面元素进行编程
- webform中如何锁定textbox的文本不允许客户端来修改
Response.Write("<script>alert('成功删除" + tmp.ToString() + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>");
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1"); if (cb.Checked)
{
int strid = int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
sb.Append("'"+strid.ToString()+"',");
}
}
if(sb.Length>0)
{
SqlConnection con = db.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("delete from cwissrec where Recid in (" + sb.ToString().TrimEnd(",".ToCharArray()) + ")", con);
int delnum = cmd.ExecuteNonQuery();
Response.Write("<script>alert('成功删除" + delnum + "条数据,现在将为您转到资源列表');window.document.location.href='admin_RecList.aspx';</script>"); }