DropDownList - Add

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
 
A

Andre

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 !!?
 
A

addup

inserted item is overwritten by the DataSource during the databind.
add your code *after* the databind and you should be fine
 
I

intrader

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.
 
A

Andre

Woa... i did'nt know that i can insert Databind() directly without creating
a function Databind() ;o)

Everything's PERFECT.

Thank you.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top