在网上看到一些批量删除数据的例子.但是大部分是用的数组来保存所选的id.这样比较麻烦,也不容易被理解.我就拿个比较简单的方法来实现这个功能.(只看红色的部分即可,而且还加个删除提示窗口)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace overred.test
{
///
/// t1 的摘要说明。
///
public class t1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label message;
protected System.Web.UI.WebControls.LinkButton showck;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.LinkButton delall;
protected System.Web.UI.WebControls.DataGrid dg;
private OleDbCommand cmd;
private OleDbConnection conn;
protected System.Web.UI.WebControls.LinkButton lb;
private string datas;
private void Page_Load(object sender, System.EventArgs e)
{
Session["s"]="dd";
// 在此处放置用户代码以初始化页面
if(!this.Page.IsPostBack)
Sql();
}
private DataSet Getds()
{
datas="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../overred.mdb");
conn = new OleDbConnection(datas);
conn.Open();
OleDbDataAdapter adp = new OleDbDataAdapter("select * from subnews order by news_order desc", conn);
DataSet ds = new DataSet(); adp.Fill(ds,"link");
return ds;
}
private void Sql()
{
alter();
using (DataSet dss=Getds())