Home All Groups Group Topic Archive Search About

add a list item to a bound control

Author
14 Feb 2006 7:01 PM
blackstaronline.net
Hi,

I have a drop down list thats bound to a SQL query. But I want to have
the top item or .SelectedItem to be a generic "Please Select..." with
no value. I've searched for the answer and tried every combination and
can't find an answer.


I've tried adding <ASP:ListItem> to the control but the bound data
overides it.


I'm using .NET with VB, Any suggestions?

Author
14 Feb 2006 7:55 PM
DWS
Blackstar,

Sql put "Please Select..." as the first result in the querry result.
or manipulate list manually in the list data bound event.

Good Luck
DWS





Show quoteHide quote
"blackstaronline.net" wrote:

> Hi,
>
> I have a drop down list thats bound to a SQL query. But I want to have
> the top item or .SelectedItem to be a generic "Please Select..." with
> no value. I've searched for the answer and tried every combination and
> can't find an answer.
>
>
> I've tried adding <ASP:ListItem> to the control but the bound data
> overides it.
>
>
> I'm using .NET with VB, Any suggestions?
>
>
Author
14 Feb 2006 8:29 PM
Teemu Keiski
Hi,

if you use .NET 2.0, you can specify the <asp:ListItem> and then just set
AppendDataBoundItems="True", when items added with databinding would be
appended to the end.

You can also do it in code

DropDownList1.Items.Insert(0,New ListItem("Text","Value"))

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Show quoteHide quote
"blackstaronline.net" <jr***@blackstaronline.net> wrote in message
news:1139943696.551811.70110@o13g2000cwo.googlegroups.com...
> Hi,
>
> I have a drop down list thats bound to a SQL query. But I want to have
> the top item or .SelectedItem to be a generic "Please Select..." with
> no value. I've searched for the answer and tried every combination and
> can't find an answer.
>
>
> I've tried adding <ASP:ListItem> to the control but the bound data
> overides it.
>
>
> I'm using .NET with VB, Any suggestions?
>
Author
14 Feb 2006 8:58 PM
blackstaronline.net
That worked perfectly. Thank you so much!


For anyone else having the same problem, all I did is add 1 line of
code directly after binding the data to the control. It now looks like
this;

Dim objCmd as New SQLCommand(strSQL, objConn)
   objConn.Open()
   With DD_Design
      .DataTextField =  "CompanyName"
      .DataValueField = "CompanyCode"
      .DataSource =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
      .DataBind()
      .Items.Insert(0,New ListItem("Please Select...",""))
   End With

Thanks again Teemu,

Jeremy Reid
http://blackstaronline.net/hgtit