I'm databinding my DropDownList to a DataSet. How do I add a dummy record
at the top of the combo box.
In other words, suppose we are dealing with cars I want something like:
<select name="cboCars">
<option value="0">Select a car</option>
<option value="1">Ford Mustang</option>
...
<option value="5">Mitsubishi Eclipse</option>
</select
How do I get the "Select a car" option at the top, while still databinding
the DropDownList?
If I don't have the dummy record the DropDownList auto selects the first
option as the default, which isn't good for my purpose.
Thanks in advance,
Dan
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003*After* you databind, do a dropdownlist.items.add(0, "")
HTH,
Morgan
"Dan" <dhartley@.somewhere.com> wrote in message
news:%23SWskXevDHA.2372@.TK2MSFTNGP09.phx.gbl...
> I'm databinding my DropDownList to a DataSet. How do I add a dummy record
> at the top of the combo box.
> In other words, suppose we are dealing with cars I want something like:
> <select name="cboCars">
> <option value="0">Select a car</option>
> <option value="1">Ford Mustang</option>
> ...
> <option value="5">Mitsubishi Eclipse</option>
> </select>
> How do I get the "Select a car" option at the top, while still databinding
> the DropDownList?
> If I don't have the dummy record the DropDownList auto selects the first
> option as the default, which isn't good for my purpose.
> Thanks in advance,
> Dan
>
> --
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003
This is assuming you are binding via code i.e. dropdownlist.datasource =
mydataset.tables(0)
I've never done visual databinding in the WebForm designer, but you should
be able to add the dropdownlist.items.insert(0, "") (sorry, chose the wrong
method from memory) on the page_load event.
--Morgan
"Morgan" <mfears@.spamcop.net> wrote in message
news:uZHMsjevDHA.2408@.tk2msftngp13.phx.gbl...
> *After* you databind, do a dropdownlist.items.add(0, "")
> HTH,
> Morgan
> "Dan" <dhartley@.somewhere.com> wrote in message
> news:%23SWskXevDHA.2372@.TK2MSFTNGP09.phx.gbl...
> > I'm databinding my DropDownList to a DataSet. How do I add a dummy
record
> > at the top of the combo box.
> > In other words, suppose we are dealing with cars I want something like:
> > <select name="cboCars">
> > <option value="0">Select a car</option>
> > <option value="1">Ford Mustang</option>
> > ...
> > <option value="5">Mitsubishi Eclipse</option>
> > </select>
> > How do I get the "Select a car" option at the top, while still
databinding
> > the DropDownList?
> > If I don't have the dummy record the DropDownList auto selects the first
> > option as the default, which isn't good for my purpose.
> > Thanks in advance,
> > Dan
> > --
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003
Worked like a charm. I knew it had to be something simple that I was
missing.
Thanks,
Dan
"Morgan" <mfears@.spamcop.net> wrote in message
news:uIASTnevDHA.3532@.TK2MSFTNGP11.phx.gbl...
> This is assuming you are binding via code i.e. dropdownlist.datasource =
> mydataset.tables(0)
> I've never done visual databinding in the WebForm designer, but you should
> be able to add the dropdownlist.items.insert(0, "") (sorry, chose the
wrong
> method from memory) on the page_load event.
> --Morgan
> "Morgan" <mfears@.spamcop.net> wrote in message
> news:uZHMsjevDHA.2408@.tk2msftngp13.phx.gbl...
> > *After* you databind, do a dropdownlist.items.add(0, "")
> > HTH,
> > Morgan
> > "Dan" <dhartley@.somewhere.com> wrote in message
> > news:%23SWskXevDHA.2372@.TK2MSFTNGP09.phx.gbl...
> > > I'm databinding my DropDownList to a DataSet. How do I add a dummy
> record
> > > at the top of the combo box.
> > > > In other words, suppose we are dealing with cars I want something
like:
> > > > <select name="cboCars">
> > > <option value="0">Select a car</option>
> > > <option value="1">Ford Mustang</option>
> > > ...
> > > <option value="5">Mitsubishi Eclipse</option>
> > > </select>
> > > > How do I get the "Select a car" option at the top, while still
> databinding
> > > the DropDownList?
> > > > If I don't have the dummy record the DropDownList auto selects the
first
> > > option as the default, which isn't good for my purpose.
> > > > Thanks in advance,
> > > Dan
> > > > > --
> > > Outgoing mail is certified Virus Free.
> > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003
> >
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003
after you bound the DropDownList
call:
ddl.Items.Insert(0,new ListItem("Select a car","0"));
"Dan" <dhartley@.somewhere.com> ะด?
news:%23SWskXevDHA.2372@.TK2MSFTNGP09.phx.gbl...
> I'm databinding my DropDownList to a DataSet. How do I add a dummy record
> at the top of the combo box.
> In other words, suppose we are dealing with cars I want something like:
> <select name="cboCars">
> <option value="0">Select a car</option>
> <option value="1">Ford Mustang</option>
> ...
> <option value="5">Mitsubishi Eclipse</option>
> </select>
> How do I get the "Select a car" option at the top, while still databinding
> the DropDownList?
> If I don't have the dummy record the DropDownList auto selects the first
> option as the default, which isn't good for my purpose.
> Thanks in advance,
> Dan
>
> --
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment