Insert item into dropdown

C

Chris

I am trying to insert an item into a dropdown which is bound to an
sqldatasource. Nothing happens when I place the following code in page load
and render event. Is the datasource overriding my insert or am I doing
something wrong

Dim lstitemcompany As New ListItem

lstitemcompany.Text = "Select a company"

lstitemcompany.Value = ""

drpCompanies.Items.Insert(0, lstitemcompany)
 
N

neilmcguigan

do the insert in the DataBound event handler:

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
ddl.Items.Insert(0, new ListItem("text", "value"));
}
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top