Solved

Populating a Drop Down List with Items from Dataset and then adding more items...

Posted on 2003-12-05
2
861 Views
Last Modified: 2010-04-16
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()
{
 da_titles.Fill(ds_titles);
 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.DataBind();

 ddl_title_id.Items.Add(new ListItem("", "0"));
 ddl_title_id.SelectedValue = "0";
}
 
obviously:
  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 :)

cheers, sho.
0
Comment
Question by:sho_1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
testn earned 50 total points
ID: 9882103
change it to

ddl_title_id.Items.Insert(0,new ListItem("", "0"));
ddl_title_id.SelectedIndex = 0;
0
 

Author Comment

by:sho_1978
ID: 9882130
you little beuty !!! :)

points are yours, many many thanks testn (guess you never got around to changing your name) :)

sho
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question