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 66 67 68 69 70 71 72 73 74 75
|
namespace WebApplication1
{
public class Panier
{
private Dictionary<int,Produit> _Produits;
public string NomPanier;
public string CouleurPanier;
public Dictionary<int,Produit> Produits
{
get
{
if (_Produits==null)
_Produits= new Dictionary<int,Produit>();
return _Produits;
}
set
{
_Produits= value;
}
}
}
public class Produit
{
public int ID;
public string name;
}
public partial class _Default : System.Web.UI.Page
{
public Panier MonPanier
{
get
{
return (Panier)Session["Panier"];
}
set
{
Session["Panier"] = value;
}
}
protected override void OnInit(EventArgs e)
{
//intiialisation de mon appli
Session["Panier"] = new Panier();
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
//on met un peu d'info dans ce panier
Produit dent;
dent = new Produit();
dent.ID = 1;
dent.name = "dentifrice";
//on ajoute 5 dentifrices
MonPanier.Produits.Add(5, dent);
//puis en 3.5, on ajoute 10 brosses a dents
MonPanier.Produits.Add(10, new Produit{ ID=2,name="Brosse à dents" });
}
protected override void OnPreRender(EventArgs e)
{
//et maintenant je mets à jour mon repeater pour afficher mes infos
C_Rep_ContenuPanier.DataBind();
base.OnPreRender(e);
}
}
} |
Partager