常用的datagrid 删除选种的项

itemdataBind事件中

if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
DataRowView drv = e.Item.DataItem as DataRowView;
string id = Convert.ToString(drv["newid"]);
string del = string.Format("<input type='checkbox' name='del' value='{0}'/>",id);
e.Item.Cells[0].Text=del;

}

删除按钮

string ids ="";
try
{
ids = Convert.ToString(Request["del"]);
}
catch
{

ids ="";
}
if(ids!=null&&ids.Length>0)
{
string[] id = ids.Split(',');
for(int i=0;i<id.Length;i++)
{
string sql = string.Format("delete from news where newid={0}",id[i].Trim());
db.GetState(sql);

}
Response.Write(AlertM.Alert("成功删除了数据!!"));
Response.Write(AlertM.Script("document.location='newslist.aspx'"));
}
else
{
Response.Write(AlertM.Alert("没有要删除的数据!!"));

Response.Write(AlertM.Script("history.go(-1)"));
}
}

你可能感兴趣的:(sql,Go)