This is also good for copying DropDownList items to another.
Example: it will copy all the elements from DropDownList1 to DropDownList2.
Elements in DropDownList1:
<asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Text="A" Value="1"></asp:ListItem> <asp:ListItem Text="B" Value="2"></asp:ListItem> <asp:ListItem Text="C" Value="3"></asp:ListItem> <asp:ListItem Text="D" Value="4"></asp:ListItem> <asp:ListItem Text="E" Value="5"></asp:ListItem> </asp:DropDownList>
1 - First, copy DropDownList1 to the array.
ListItem[] ListitemsArray = new ListItem[DropDownList1.Items.Count]; DropDownList1.Items.CopyTo(ListitemsArray, 0);
2 - : now copy from the array to DropDownList2.
foreach (ListItem liItems in ListitemsArray) { DropDownList2.Items.Add(liItems); }
This works for me !!!!!!!!!!!!!
Armaan
source share