1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
private void Page_Load(object sender, System.EventArgs e)
{
..........
// Si je charge ma page pour la première fois, je définis ma datatable
if (Session["DataTable"] == null)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("Produit", typeof(string)));
dt.Columns.Add(new DataColumn("MasseNette", typeof(string)));
dt.Columns.Add(new DataColumn("EtatPhysique", typeof(string)));
Session["DataTable"] = dt;
}
else
{
dt = (DataTable) Session["DataTable"];
}
dv = new DataView(dt);
datagrid1.DataSource = dv;
// Placer ici le code utilisateur pour initialiser la page
if (!Page.IsPostBack)
{
.........
}
}
// Ajout des produits de la zone d'édition dans la datagrid
private void BtnAjouter_Click(object sender, System.EventArgs e)
{
if (CtrlChampProduits() == 0)
{
AjoutProduitInDataGrid(DropDownListProduit1.SelectedValue,TextBoxMasseNette1.Text + " " + DropdownlistMasseNette1.SelectedValue,DropDownListEtatPhysique1.SelectedValue);
DropDownListProduit1.SelectedValue = "---";
TextBoxMasseNette1.Text = "";
DropdownlistMasseNette1.SelectedIndex = 0;
DropDownListEtatPhysique1.SelectedIndex = 0;
}
else
{
Page.RegisterStartupScript("key","<script language=javascript>window.open('Erreur.aspx','Test','location=no,directories=no,menubar=no,resizable=no,scrollbars=no,status=no,height=35,width=400');</script>");
}
datagrid1.DataBind();
}
private void AjoutProduitInDataGrid(string Produit, string MasseNette,string EtatPhysique)
{
DataRow dr = dt.NewRow();
dr["Produit"] = Produit;
dr["MasseNette"] = MasseNette;
dr["EtatPhysique"] = EtatPhysique;
dt.Rows.Add(dr);
datagrid1.DataBind();
} |
Partager