I have an array of type Person, which contains string objects: FirstName, LastName, login.
I have this bound to a dropdownlist.
Now along with this array, I also want to display one more item called “Desk”. How can i do that?
My current code is:
Person[] traders = GetTraders();
ddl_trader.Items.Clear();
ddl_trader.DataSource = traders;
ddl_trader.DataTextField = "LastName";
ddl_trader.DataValueField = "Login";
ddl_trader.DataBind();
I also want that one extra item I’m adding to be the default selected item.
You can set the
AppendDataBoundItemsproperty totrue(it’sfalseby default), add your item manually, then do the databinding process to add the remaining items.AppendDataBoundItemsdetermines if the list is cleared during databinding or not.if you need to add the new item after the list has been bound, you can do
this does not require setting
AppendDataBoundItemstotrue.