Solved

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

Posted on 2003-12-05
2
855 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
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Aspnet xml 2 36
Windows Service with UDP 2 28
Data Saving(2) 2 26
C# Error - Add Failed 12 39
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now