G
Guest
Hi,
I have a ListItemCollection that I bind to DropDownList:
ListItemCollection items = new ListItemCollection();
ListItem item;
item = new ListItem("Option 1", "1");
items.Add(item);
item = new ListItem("Option 2", "2");
item.Selected = true;
items.Add(item);
ddl1.DataSource = items;
ddl1.DataBind();
As you see the second ListItem is selected and should be selected in the
dropdownlist. But isn't!
However, if i use:
<asp
ropDownList runat="server" ID="test2">
<asp:ListItem Text="1" />
<asp:ListItem Selected="True" Text="2" />
</asp
ropDownList>
Everything works as expected.
Is there an explanation to this? And is there a possible solution? I guess
one could put the selected ListItem fist in the DropDownList but this would
mess up the option and isn't a good solution for me.
Thanks in advance
Richard
I have a ListItemCollection that I bind to DropDownList:
ListItemCollection items = new ListItemCollection();
ListItem item;
item = new ListItem("Option 1", "1");
items.Add(item);
item = new ListItem("Option 2", "2");
item.Selected = true;
items.Add(item);
ddl1.DataSource = items;
ddl1.DataBind();
As you see the second ListItem is selected and should be selected in the
dropdownlist. But isn't!
However, if i use:
<asp
<asp:ListItem Text="1" />
<asp:ListItem Selected="True" Text="2" />
</asp
Everything works as expected.
Is there an explanation to this? And is there a possible solution? I guess
one could put the selected ListItem fist in the DropDownList but this would
mess up the option and isn't a good solution for me.
Thanks in advance
Richard