Bonjour,
Voici mon problème:
A partir d'une source XML je remplis un tableau (tabLogin) dynamiquement en y ajoutant un control CheckBox. De cette manière, toutes les lignes du tableau qui ont été cochées sont traitées après avoir fait un click sur le bouton 'btnEnvoyer'.
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
TableRow tr = new TableRow();
System.Web.UI.WebControls.CheckBox ch;
TableRow tRow;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        DataXML._rootPath = HttpContext.Current.Server.MapPath("~\\App_Data\\");
        XPathNodeIterator monIter = DataXML.SearchXmlByIterator("//membre[Actif='Oui']", "XMLMembres.xml");
        for (int i = 0; i < monIter.Count; i++)
        {
            monIter.MoveNext();
            tRow = new TableRow();
            tabLogin.Rows.Add(tRow);
            for (int j = 1; j < 7; j++)
            {
                TableCell tCell = new TableCell();
                if (j == 1)
                {
                    monIter.Current.MoveToAttribute("Id", "");
                    tCell.Text = monIter.Current.Value;
                    monIter.Current.MoveToParent();
                }
                if (j == 2)
                {
                    tCell.Text = monIter.Current.SelectSingleNode("./Nom").Value;
                 }
                if (j == 3)
                {
                    tCell.Text = monIter.Current.SelectSingleNode("./Prénom").Value;
                 }
                if (j == 4)
                {
                    tCell.Text = monIter.Current.SelectSingleNode("./Courriel").Value;
                 }
                if (j == 5)
                {
                    tCell.Text = monIter.Current.SelectSingleNode("./MotDePasse").Value;
                }
                if (j == 6)
                {
                     // Créé un Checkbox Web control l'ajouter à la cellule.
                    ch = new CheckBox();
                    ch.ID = "checkBox_" + i.ToString();
                    tCell.Controls.Add(ch);
                    ch.Checked = false;
                }
                tRow.Cells.Add(tCell);
            }
        }
    }
//Bouton 'Envoyer'
protected void btnEnvoyer_Click(object sender, EventArgs e)
    {
        int iNombre = tabLogin.Rows.Count;
        for (int i = 0; i < iNombre; i++)
        {
            if (i != 0)
            {
                if (tabLogin.Rows[i].Cells[5].Text == "true") 
                {
                     //TODO: Méthode pour traiter les lignes cochées
                 }
             }
        }
    }
Seulement voilà, impossible de déterminer si un checkBox a été coché ou non.
Pourtant la lecture du tableau se fait quand même côté client ! Comment atteindre le checkBox installé dans la cellule ?