DataBound dropdownlist + extra Item

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys

I've got a dropdownlist which is being databound to an sqldatareader at
runtime. I want to add an extra Item to the list, not from the database.

I know I can do this with

ddl1.Items.Add(new ListItem("text", "value"));

works fine. However, if I put this above my DataBinding code, it doesn't
appear. After it it appears at the end of the list fine.

Question is, how do I databind AND get this item to the top of my list? It's
an ALL option y'see.

Cheers for any help!


Dan
 
ddlLocation.DataSource = Line.GetBrandingLocations

ddlLocation.DataValueField = "BrandingLocationID"

ddlLocation.DataTextField = "BrandingLocation"

ddlLocation.DataBind()

'the following line inserts at position 0

ddlLocation.Items.Insert(0, "(Select)")
 
Thanks SImon, worked great.


Dan

Simon Hazelton said:
ddlLocation.DataSource = Line.GetBrandingLocations

ddlLocation.DataValueField = "BrandingLocationID"

ddlLocation.DataTextField = "BrandingLocation"

ddlLocation.DataBind()

'the following line inserts at position 0

ddlLocation.Items.Insert(0, "(Select)")
 
Dan,

Do the databinding first and then call

ddl1.Items.Insert(0, new ListItem("text", "value"));

Eliyahu
 
Back
Top