DropDownList - Add

  • Thread starter Thread starter Andre
  • Start date Start date
A

Andre

Hi,

I'm using the DataSource and SqlDataSource to insert value in my
dropdownlist, but i want to add a -- Please Select -- at the top of the
list, but can't find a way to make it.

<asp:DropDownList ID="ddTown" runat="server" DataSourceID="SqlDataSource1"
DataTextField="idTown" DataValueField="idTown"></asp:DropDownList>

Here's some try i've made, with no success :

ddTown.Items.Add("-- Please select --")
ddTown.Items.Add(New ListItem("-- Please select --"))
ddTown.Items.Insert(0, New ListItem("-- Please select --"))
ddTown.Items.Insert(0, "-- Please select --")

Did someone have a way to make it ?

Thank you
 
The code is in the Page_Load Sub...

Work very well if i delete the DataSource of the DropDownlist... maybe my
inserted item is overwrited by the DataSource !!?
 
inserted item is overwritten by the DataSource during the databind.
add your code *after* the databind and you should be fine
 
The code is in the Page_Load Sub...

Work very well if i delete the DataSource of the DropDownlist... maybe my
inserted item is overwrited by the DataSource !!?
It gets overwritten.
What you need is to insert into the datasource.
 
Woa... i did'nt know that i can insert Databind() directly without creating
a function Databind() ;o)

Everything's PERFECT.

Thank you.
 
Back
Top