Comment créer et insérer une template
Bonjour à tous,
Me revoila, plus perdu que jamais.
J'essaye désespérement d'afficher mon objet via une template et un repeater.
J'ai déjà chercher sur le web mais je ne trouve que peux d'info et à chaque fois, ça ne correspond pas. C'est pourquoi je passe par le forum...
Je pense que le plus simple est encore de vous mettre les codes.
Donc voici ma class pour les templates :
Code:
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
|
public class Template_Tableau : ITemplate
{
static int itemcount = 0;
ListItemType templateType;
// -------------------------- CONSTRUCTEUR -------------------------------
public Template_Tableau(ListItemType type)
{
templateType = type;
}
// --------------------------- METHODES ----------------------------------
public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
switch (templateType)
{
case ListItemType.Header:
lc.Text = "<TABLE border=1><tr>";
lc.Text +="<td>Ressources</td><td>UT</td>";
lc.Text +="<td>Sem.01</td><td>Sem.02</td><td>Sem.03</td><td>Sem.04</td><td>Sem.05</td>";
lc.Text +="<td>Sem.06</td><td>Sem.07</td><td>Sem.08</td><td>Sem.09</td><td>Sem.10</td>";
lc.Text +="<td>Sem.11</td><td>Sem.12</td><td>Sem.13</td><td>Sem.14</td><td>Sem.15</td>";
lc.Text +="<td>Sem.16</td><td>Sem.17</td><td>Sem.18</td><td>Sem.19</td><td>Sem.20</td>";
lc.Text +="<td>Sem.21</td><td>Sem.22</td><td>Sem.23</td><td>Sem.24</td><td>Sem.25</td>";
lc.Text +="<td>Sem.26</td><td>Sem.27</td><td>Sem.28</td><td>Sem.29</td><td>Sem.30</td>";
lc.Text +="<td>Sem.31</td><td>Sem.32</td><td>Sem.33</td><td>Sem.34</td><td>Sem.35</td>";
lc.Text +="<td>Sem.36</td><td>Sem.37</td><td>Sem.38</td><td>Sem.39</td><td>Sem.40</td>";
lc.Text +="<td>Sem.41</td><td>Sem.42</td><td>Sem.43</td><td>Sem.44</td><td>Sem.45</td>";
lc.Text +="<td>Sem.46</td><td>Sem.47</td><td>Sem.48</td><td>Sem.49</td><td>Sem.50</td>";
lc.Text +="<td>Sem.51</td><td>Sem.52</td></tr>";
break;
case ListItemType.Item:
lc.Text = "<TR><TD>COUCOU</TD></TR>";
break;
case ListItemType.Footer:
lc.Text = "</TABLE>";
break;
}
container.Controls.Add(lc);
itemcount += 1;
}
private HtmlTableCell CreerCellule(string _strTexte)
{
HtmlTableCell objCell = new HtmlTableCell();
objCell.InnerText = _strTexte;
return objCell;
}
} |
Ma classe contenu :
Code:
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
class Contenu
{
// -------------------------- LES ATTRIBUTS -------------------------------
private string _ressource;
private int _ut;
private int _id;
private int _annee;
private Quart_Jours[] _tableau;
private int m_nSomme = 0;
private bool m_bSommeRenseignee = false;
// -------------------------- LES ACCESSEURS -------------------------------
public string Ressources
{
get { return _ressource; }
set { _ressource = value; }
}
public int Ut
{
get { return _ut; }
set { _ut = value; }
}
public int Id
{
get { return _id; }
set { _id = value; }
}
public int Annee
{
get { return _annee; }
set { _annee = value; }
}
public Quart_Jours[] Tableau
{
get { return _tableau; }
set { _tableau = value; }
}
public int Somme
{
get
{
if (!m_bSommeRenseignee)
{
m_nSomme = 0;
for (int i = 0; i < this.Tableau.Length; i++)
{
m_nSomme += Tableau[i].NbQuartJours;
}
}
return m_nSomme;
}
set
{
m_nSomme = value;
}
}
// -------------------------- CONSTRUCTEURS ---------------------------------
public Contenu()
{
Initialisation();
}
public Contenu(string maRessource, int monUt, int monId, int[] monTableau)
{
Initialisation();
for (int i = 0; i < monTableau.Length; i++)
{
_tableau[i].NbQuartJours = monTableau[i];
}
}
public Contenu(string maRessource, int monUt, int monId, int[] monTableau, int _nSomme)
{
m_nSomme = _nSomme;
m_bSommeRenseignee = true;
Initialisation();
for (int i = 0; i < monTableau.Length; i++)
{
_tableau[i].NbQuartJours = monTableau[i];
}
}
// -------------------------- LES METHODES ---------------------------------
public override string ToString()
{
return String.Format("UT : {0} \nRESSOURCE : {1} \nID : {2} \nANNEE : {3} \nTABLEAU : {4}", _ut, _ressource, _id, _annee, _tableau[16].ToString());
}
private void Initialisation()
{
_tableau = new Quart_Jours[52];
for (int i = 0; i < _tableau.Length; i++)
{
_tableau[i] = new Quart_Jours();
}
}
}
class Quart_Jours
{
private int _nbQuartJours;
public int NbQuartJours
{
get { return _nbQuartJours; }
set { _nbQuartJours = value; }
}
public override string ToString()
{
if (NbQuartJours <= 0)
{
return "";
}
else
{
return NbQuartJours.ToString();
}
}
} |
Ma class liste :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
class Liste
{
private List<Contenu> _recupObjet;
public List<Contenu> RecupObjet
{
get { return _recupObjet; }
set { _recupObjet = value; }
}
} |
mon code behind :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
protected void Page_Load(object sender, EventArgs e)
{
RptGen.HeaderTemplate = new Template_Tableau(ListItemType.Header);
// RptGen.ItemTemplate = new Template_Tableau(ListItemType.Item);
RptGen.FooterTemplate = new Template_Tableau(ListItemType.Footer);
//sqlDataAdapter1.Fill(dataSet11);
RptGen.DataBind();
//this.RecupListe();
} |
et pour finir mon code aspx :
Code:
1 2 3 4 5 6 7 8 9
|
<body>
<form id="form1" runat="server">
<div style="height: 246px; width: 964px">
<asp:Repeater ID="RptGen" runat="server">
</asp:Repeater>
</div>
</form>
</body> |
Nous avons donc un objet liste qui reccupére une liste d'objet contenu et mon but est de les afficher dans un tableau ligne par ligne.
Voila, j'espère avoir été assé clair.
Merci d'avance pour votre aide.