"Jim Florence" <fl************@hotmail.comwrote in message
news:45**********************@ptn-nntp-reader02.plus.net...
Jim,
I've just add a couple of dropdowns to my ASP form, set up a sqldatasource
and bound to the dropdown and it all works great.
I want the first item of the dropdown to be blank soa fter reading a few
articles the DropDownList1.SelectedIndex = -1 seems the way to go.
I've tried setting this oin the asp page and on a page load event in the
vb behind but I still cant get a blank dropdown
Any pointers gratefully received I'm sure I'm missing something simple
It's not so much that you're missing something simple, it's more the fact
that you're using the SqlDataSource control... This is supposed to make
database integration "simpler", which it does, but in doing so loses a whole
set of functionality which is possible if you don't use it...
If you were to bind your DropDownList programatically rather than
declaratively, you could accomplish what you require with just one extra
line of code e,g,
MyDropDownList.DataSource = <fetch dataset from database>;
MyDropDownList.DataValueField = <field from dataset>;
MyDropDownList.DataTextField = <field from dataset>;
MyDropDownList.DataBind();
That takes care of the databinding.
Now, to add a blank option at the top of the list, all you need is:
MyDropDownList.Items.Insert(0, new ListItem("", ""));