1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
public void Delete_OnClick(object sender, System.EventArgs e)
{for(int i = 0;i < DataGrid1.Items.Count;i++)
{ DataGridItem dgi= DataGrid1.Items[i];
if(dgi.ItemType==ListItemType.Item||
Type==ListItemType.AlternatingItem)
{CheckBox MyCheckBox=(CheckBox)dgi.FindControl("DelChk");
if(MyCheckBox.Checked==true)
{String idProduct= DataGrid1.DataKeys[dgi.ItemIndex].ToString();
String sSQL1="DELETE from Produit where ID_Produit="+idP;
SqlCommand myCommand= new SqlCommand(sSQL1,sqlConnection1);
myCommand.Connection.Open();
try{myCommand.ExecuteNonQuery();
DataGrid1.EditItemIndex=-1;
}
catch(SqlException exc){Message.Text="ERREUR : Impossible de supprimer l'enregistrement";}
BindGrid();
myCommand.Connection.Close();
lblDonnees.Text=idP;
} |
Partager