List Info

Thread: A Blank entry in a DropDownList...




A Blank entry in a DropDownList...
country flaguser name
United States
2007-06-05 09:59:57
Hi All,

I have a question. Suppose I have a dropdownlist which is
bound to a
dataset and it has a few values in it...

 

The first time I display the form, I would have liked to
have a blank
entry in the dropdownlist - the blank being an indication
that the user
has not yet selected anything and that he must select
something.

My problem is that I'm binding a dataset to the dropdown
list and the
dataset does not have a blank row in it. 

 

How do I create a blank entry in a drop down list given the
above
situation? Do I have to add a blank record to the dataset
that I'm
binding it with?

If so how do I do that?

Or, is there an option with dropdownlists for the control to
have a
blank option? (I've looked but can't find anything).

Or is there a better "conceptual" way of going
about this to begin with?

 

Thanks,

Jan


To read FirstRand Bank's Disclaimer for this email click on
the following address or copy into your Internet browser: 
https://www.fnb
.co.za/disclaimer.html 

If you are unable to access the Disclaimer, send a blank
e-mail to
firstrandbankdisclaimerfnb.co.za and we will send you a copy of
the Disclaimer.



--- List Settings ---
http://aspadvice.com/list
s/


RE: A Blank entry in a DropDownList...
country flaguser name
United States
2007-06-05 10:17:34
dropdown.Insert(0,new ListItem(""))

----- Original Message ----- 
From: "Lamprecht, Jan" <JLamprecht1fnb.co.za>
To: <aspnetaspadvice.com>
Sent: Tuesday, June 05, 2007 4:59 PM
Subject: [aspnet] A Blank entry in a DropDownList...


> Hi All,
>
> I have a question. Suppose I have a dropdownlist which
is bound to a
> dataset and it has a few values in it...
>
>
>
> The first time I display the form, I would have liked
to have a blank
> entry in the dropdownlist - the blank being an
indication that the user
> has not yet selected anything and that he must select
something.
>
> My problem is that I'm binding a dataset to the
dropdown list and the
> dataset does not have a blank row in it.
>
>
>
> How do I create a blank entry in a drop down list given
the above
> situation? Do I have to add a blank record to the
dataset that I'm
> binding it with?
>
> If so how do I do that?
>
> Or, is there an option with dropdownlists for the
control to have a
> blank option? (I've looked but can't find anything).
>
> Or is there a better "conceptual" way of
going about this to begin with?
>
>
>
> Thanks,
>
> Jan
>
>
> To read FirstRand Bank's Disclaimer for this email
click on the following 
> address or copy into your Internet browser:
> https://www.fnb
.co.za/disclaimer.html
>
> If you are unable to access the Disclaimer, send a
blank e-mail to
> firstrandbankdisclaimerfnb.co.za and we will send
you a copy of the 
> Disclaimer.
>
>
>
> --- List Settings ---
> http://aspadvice.com/list
s/ 



--- List Settings ---
http://aspadvice.com/list
s/


Re: A Blank entry in a DropDownList...
user name
2007-06-05 10:22:47
Jan,
&nbsp;
Go ahead and bind your dataset to the DropDownList then insert a new item manually in the code behind.
 
i.e.
&nbsp;
DropDownList.DatSource = mySet;
DropDownList.DataBind();
 ;
DropDownList.Items.Add (new ListItem ("<;--- Please Select One --->&quot;, string.Empty);
&nbsp;
Hope this helps!

&nbsp;
On 6/5/07, Lamprecht, Jan < JLamprecht1fnb.co.za">JLamprecht1fnb.co.za> wrote:
Hi All,

I have a question. Suppose I have a dropdownlist which is bound to a
dataset and it has a few values in it...



The first time I display the form, I would have liked to have a blank
entry in the dropdownlist - the blank being an indication that the user
has not yet selected anything and that he must select something.

My problem is that I'm binding a dataset to the dropdown list and the
dataset does not have a blank row in it.



How do I create a blank entry in a drop down list given the above
situation? Do I have to add a blank record to the dataset that I'm
binding it with?

If so how do I do that?

Or, is there an option with dropdownlists for the control to have a
blank option? (I've looked but can't find anything).

Or is there a better "conceptual"; way of going about this to begin with?



Thanks,

Jan


To read FirstRand Bank's Disclaimer for this email click on the following address or copy into your Internet browser:
https://www.fnb.co.za/disclaimer.html

If you are unable to access the Disclaimer, send a blank e-mail to
firstrandbankdisclaimerfnb.co.za">firstrandbankdisclaimerfnb.co.za and we will send you a copy of the Disclaimer.



--- List Settings ---
http://aspadvice.com/lists/




--
David J. Gottlieb
Member - ASPInsiders
DevAdvice.com - "Answers to questions&quot;
ASPAlliance.com
Project Management Suite - http://projectmanagementsuite.com
http://davidg.tiddlyspot.com
http://thegottliebclan.com --- List Settings --- http://aspadvice.com/lists/
RE: A Blank entry in a DropDownList...
country flaguser name
United States
2007-06-15 12:56:51
I realize this is a late entry into this thread, but this
same requirement
came up for me today and in discussing various options
presented here and
discussion with our DBA, we have opted to use a UNION ALL
statement to
insert the "default" option into the results of
the SELECT statement.  

The reason for opting for this method, is that if we ever
need to change the
text or values for the select, we can do so without having
to recompile and
deploy the web site, but will only need to change the values
in the stored
procedure in the database.

Here is a simple example to get a list of groups for a given
client with a
default option:

	SELECT	Group_ID, 
			[Name]
	FROM	tbl_Groups
	WHERE	Client_ID=Client_ID
	UNION ALL
	(Select 0, '--Selected a Group--')
	ORDER BY Group_ID


The list.Add and List.Insert methods do work well, however.

Again, sorry for the late post.

Duane

-----Original Message-----
From: Lamprecht, Jan [mailto:JLamprecht1fnb.co.za] 
Sent: June 05, 2007 10:00 AM
To: aspnetaspadvice.com
Subject: [aspnet] A Blank entry in a DropDownList...

Hi All,

I have a question. Suppose I have a dropdownlist which is
bound to a dataset
and it has a few values in it...

 

The first time I display the form, I would have liked to
have a blank entry
in the dropdownlist - the blank being an indication that the
user has not
yet selected anything and that he must select something.

My problem is that I'm binding a dataset to the dropdown
list and the
dataset does not have a blank row in it. 

 

How do I create a blank entry in a drop down list given the
above situation?
Do I have to add a blank record to the dataset that I'm
binding it with?

If so how do I do that?

Or, is there an option with dropdownlists for the control to
have a blank
option? (I've looked but can't find anything).

Or is there a better "conceptual" way of going
about this to begin with?

 

Thanks,

Jan


To read FirstRand Bank's Disclaimer for this email click on
the following
address or copy into your Internet browser: 
https://www.fnb
.co.za/disclaimer.html 

If you are unable to access the Disclaimer, send a blank
e-mail to
firstrandbankdisclaimerfnb.co.za and we will send you a copy of
the
Disclaimer.



--- List Settings ---
http://aspadvice.com/list
s/





--- List Settings ---
http://aspadvice.com/list
s/


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )