Ajouter une ligne dans un tableau en cliquant sur un bouton

MilenaKasaka Messages postés 3 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 6 mai 2009 - 5 mai 2009 à 15:13
MilenaKasaka Messages postés 3 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 6 mai 2009 - 6 mai 2009 à 10:59
Bonjour,

J'ai créé un formulaire avec un tableau.

Je souhaiterais que l'utilisateur puisse ajouter de nouvelles lignes au tableau en cliquant sur un bouton.

J'ai essayer deux possibilités :
1- L'utilisateur clique autant de fois sur un même bouton qu'il veut ajouter de ligne.
2- Un nouveau bouton est inséré dans chaque ligne et est lié à la même méthode.

Malheureusement aucune des deux possibilités ne fonctionne.

Merci d'avance à tous ceux qui pourraient m'éclairer.

4 réponses

titeoe Messages postés 433 Date d'inscription samedi 26 avril 2003 Statut Membre Dernière intervention 4 décembre 2009 1
6 mai 2009 à 09:01
Bonjour,

la méthode 1 me parait etre la bonne. Qu'entends tu par "ca ne fonctionne pas" ?
0
MilenaKasaka Messages postés 3 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 6 mai 2009
6 mai 2009 à 09:19
Pour la méthode 1, au premier clic sur le bouton, une ligne est ajoutée mais au deuxième clic rien ne se passe.

Pour la méthode 2, quand on clique sur le deuxième bouton, la deuxième ligne est supprimée.
0
titeoe Messages postés 433 Date d'inscription samedi 26 avril 2003 Statut Membre Dernière intervention 4 décembre 2009 1
6 mai 2009 à 10:13
quel est le code que tu met derriere le bouton ?
0
MilenaKasaka Messages postés 3 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 6 mai 2009
6 mai 2009 à 10:59
Voilà le code de la deuxième solution :


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /><link rel="File-List" href="file:///C:%5Ctemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><style><!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
--></style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tableau Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /><link rel="File-List" href="file:///C:%5Ctemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" /><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><style><!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
--></style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tableau Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->privatevoid plusButton_Click(object
sender, System.EventArgs e)

{

           

HtmlTableRow
newRow = new HtmlTableRow();

 

      // Collection
qui contient les TextBox de la ligne

      Hashtable champs = new Hashtable();

 

      // Pour chacune
des 5 colonnes

      for (int i=0 ; i<5 ; i++)

      {

            TextBox tb = new TextBox();

            HtmlTableCell cell;

            cell = new
HtmlTableCell();

 

            switch
(i)

            {

                  case
0:

                        cell.Controls.Add(tb);

                        champs.Add("dateDebut",tb);

                        break;

                  case
1:

                        cell.Controls.Add(tb);

                        champs.Add("dateFin",tb);

                        break;

                  case
2:

                        cell.Controls.Add(tb);

                        champs.Add("lieu",tb);

                        break;

                  case
3:

                        cell.Controls.Add(tb);

                        champs.Add("observations",tb);

                        break;

                  case
4:

                        Button bt = new Button();

                        bt.Text = "Ajouter
une ligne";

                        bt.Click += new System.EventHandler(this.plusButton_Click);

                        cell.Controls.Add(bt);

                        break;

                  default:

                        break;

            }

                       

            newRow.Cells.Add(cell);

      }

 

      tableau_nouvelles_rsv.Controls.Add(newRow);

      lignesAjoutees.Add(champs);

 

                 

 

      //plusButton.Click
+= new System.EventHandler(this.plusButton_Click);

 

}
0
Rejoignez-nous