好了,我改好了!这样就行了!
try
{
conn=new SqlConnection(ConfigurationSettings.AppSettings["sqlConn"]);
string myid="";
for(int i=0;i<DataGrid1.Items.Count;i++)
{
CheckBox cb=(CheckBox)this.DataGrid1.Items[i].FindControl("ck");
if(cb.Checked==true)
{
myid+=DataGrid1.DataKeys[i].ToString() +",";
}
}
myid=myid.Substring(0,myid.Length-1);
string sql="delete SD_AddAnnouce where id in ("+myid.ToString() + ")";
conn.Open();
SqlCommand comm=new SqlCommand(sql,conn);
comm.ExecuteNonQuery();
Response.Write("<script>alert('删除公告成功!')</script>");
conn.Close();
dgbind();
}
catch(Exception err)
{
Response.Write(err.ToString());
}