Can not add to/modify dropdown list after datasource has been load

G

Guest

Hi,

In my dropdown I bind to a datasource. After that I try to do one of the
following:
1. Add an Item to the dropdown using dd.Items.Add(newe ListItem("textstr"));
2. Change the text of an existing item in the dropdown. For this one I use
the
following:pubDD.Items[pubDD.Items.IndexOf(pubDD.Items.FindByText("textstr"))].Text=otherText;

Neither one works.

Thanks for any suggestions....
 
G

Guest

Thanks but it didn't work:
pubDD.Items.Insert(recCnt,new ListItem( "WINK", recCnt.ToString())); For
the new insert
That's for inserting a new one.

Modifying an existing one didn't work either.

Steve C. Orr said:
After databinding try dd.Items.Insert(...)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Merdaad said:
Hi,

In my dropdown I bind to a datasource. After that I try to do one of the
following:
1. Add an Item to the dropdown using dd.Items.Add(newe
ListItem("textstr"));
2. Change the text of an existing item in the dropdown. For this one I
use
the
following:pubDD.Items[pubDD.Items.IndexOf(pubDD.Items.FindByText("textstr"))].Text=otherText;

Neither one works.

Thanks for any suggestions....
 
G

Guest

any other ideas?

Merdaad said:
Thanks but it didn't work:
pubDD.Items.Insert(recCnt,new ListItem( "WINK", recCnt.ToString())); For
the new insert
That's for inserting a new one.

Modifying an existing one didn't work either.

Steve C. Orr said:
After databinding try dd.Items.Insert(...)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Merdaad said:
Hi,

In my dropdown I bind to a datasource. After that I try to do one of the
following:
1. Add an Item to the dropdown using dd.Items.Add(newe
ListItem("textstr"));
2. Change the text of an existing item in the dropdown. For this one I
use
the
following:pubDD.Items[pubDD.Items.IndexOf(pubDD.Items.FindByText("textstr"))].Text=otherText;

Neither one works.

Thanks for any suggestions....
 
S

Steve C. Orr [MVP, MCSD]

You don't have to use databinding.
You can iterate through the datasource and add each item to the dropdownlist
with a few lines of code.
Then you can add anything you want without such hassles.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Merdaad said:
any other ideas?

Merdaad said:
Thanks but it didn't work:
pubDD.Items.Insert(recCnt,new ListItem( "WINK", recCnt.ToString())); For
the new insert
That's for inserting a new one.

Modifying an existing one didn't work either.

Steve C. Orr said:
After databinding try dd.Items.Insert(...)

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Hi,

In my dropdown I bind to a datasource. After that I try to do one of
the
following:
1. Add an Item to the dropdown using dd.Items.Add(newe
ListItem("textstr"));
2. Change the text of an existing item in the dropdown. For this one
I
use
the
following:pubDD.Items[pubDD.Items.IndexOf(pubDD.Items.FindByText("textstr"))].Text=otherText;

Neither one works.

Thanks for any suggestions....
 
Joined
Nov 7, 2006
Messages
1
Reaction score
0
Set appendDataBoundItems

Do as above but set the property 'appenDataBoundItems' on the dropdownlist,
this merge the data from the database with your static bound item.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top