public void DataList_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
aa=Convert.ToString(DataList1.DataKeys[e.Item.ItemIndex]);
//System.ArgumentOutOfRangeException:索引超出范围,必须为非负值并小于集合大小.参数名: index
string str="select count(*) from users where users.dep_id='" + aa + "'";
com=new SqlCommand(str,conn);
conn.Open();
int Count=Convert.ToInt32(com.ExecuteScalar());
if(Count==0)
{
Delete();
}
else Response.Write("<script>javascript:alert('该部门里还有员工,不允许删除!!!');window.location='dep_manage.aspx'</script>");
conn.Close();
}
private void Delete()
{
string sql="delete from dep where dep_id='" + aa + "'";
com1=new SqlCommand(sql,conn);
com1.ExecuteNonQuery();
conn.Close();
ListBind();
}
[此贴子已经被作者于2007-6-2 17:36:49编辑过]