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

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
 
L

Lars Netzel

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
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top