DropDownList: possible to add new rows after the DataSource has been set?

  • Thread starter Thread starter Jim Bancroft
  • Start date Start date
J

Jim Bancroft

Hi everyone,

I'm have a DropDownList that populates itself from a DataTable. Is
there some way to "append" additional rows after the datasource has been
attached? For example, I'd like to bind my DropDown, then add an extra row
for a default entry that'll appear no matter what data is retrieved.

I've looked around but didn't see an Add() method I could use. Is what
I'm asking possible, or is it the case you're out of luck after binding your
datasource? Thanks for the help.

-Jim
 
What you want is easy.. and there definately is an Add() method.

With this you add an item which will end up in the bottom of the list:
DropDownList1.Items.Add("Select an item")

Wíth this you will insert an item in the top (index 0):
DropDownList1.Items.Insert(0,"Select an item")

OR...if you need to create an item that also has a value, since most Items
you have in a dropdownbox should return a value instead of a text.
DropDownList1.Items.Insert(0, New ListItem("Select an item", "VALUE"))

Questions?

Best regards/
Lars Netzel
 
Jim,

In situations like yours I add rows to the DataTable after filling in with
data from the database. Then I bind the list to the table in a regular way.

Eliyahu
 
Back
Top