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
|
protected static int count; //compte le nombre de liste deroulante a creer
protected static DropDownList[] ddl;
//creation des liste deroulante
protected void Page_PreInit(object sender, EventArgs e)
{
ddl = new DropDownList[count];
for (int i = 0; i < count; i++)
{
ddl[i] = new DropDownList();
ddl[i].ID = "ddl"+i;
ListItem li = new ListItem("un","1");ddl[i].Items.Add(li);
ListItem li2 = new ListItem("deux","2");ddl[i].Items.Add(li2);
ListItem li3 = new ListItem("trois", "3"); ddl[i].Items.Add(li3);
form1.Controls.Add(ddl[i]);
}
}
//increment le nombre de dropdownlist
protected void Button1_Click(object sender, EventArgs e)
{
count++;
}
// permet d'afficher les item selectionné
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
for (int i = 0; i < count; i++)
{
Label1.Text += ddl[i].SelectedItem.Text;
}
} |
Partager