Populating a Drop Down List with Items from Dataset and then adding more items...
Posted on 2003-12-05
okay... a question for you...
I have a DropDownList called ddl_title_id
I populate this DropDownList with the following method...
private void populate_ddl_title_id()
ddl_title_id.DataSource = ds_titles;
ddl_title_id.DataMember = "titles_select";
ddl_title_id.DataValueField = "title_id";
ddl_title_id.DataTextField = "title";
ddl_title_id.Items.Add(new ListItem("", "0"));
ddl_title_id.SelectedValue = "0";
da_titles is a dataadapter
ds_titles is a dataset
titles_select is a stored procedure within the dataadapter
now here's my question...
as you can see from my code above once i've got all the values from my dataset then i add a blank item also with a value of 0 and text of "".
how can i re-order the DropDownList items so that the final item I add is at the top of the list?
before you reply consider this... i know how to loop around a recordset and populate like that, but i'd like to use a dataset to populate my DropDownList.
willing to consider any neat solution, but please don't suggest any of the following unless you have a very strong argument for doing so....
- i don't want to make changes to my stored procedure
- i don't want to add a blank record to my titles table
- don't suggest adding my blank item before i populate with my dataset as it wipes any current items.
so... what's the solution someone.... please :)