473,379 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

asp:dropdownlist

When I bind the dropdownlist-control to a datareader, it displays all the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of the
dropdownlist? I want the first choice in the dropdownlist to be "blank" (no
value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)
Jan 31 '06 #1
5 2041
I didn't test this, but I'm pretty sure this is what you have to do. After
the DataBind line of code, add:

Me.drpCompany.items.insert(0,"")

"Øyvind Isaksen" <oy****@webressurs.no> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
When I bind the dropdownlist-control to a datareader, it displays all the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of the
dropdownlist? I want the first choice in the dropdownlist to be "blank"
(no value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)

Jan 31 '06 #2
Yes, this inserted a blank in the top of the dropdownlist.
But, I only want the value to be blank (""), now the value AND text is
blank. Do you know how I get the text = "choose"...? (And still value = "")

Thanks!!
"Kim Quigley" <ki********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
I didn't test this, but I'm pretty sure this is what you have to do. After
the DataBind line of code, add:

Me.drpCompany.items.insert(0,"")

"Øyvind Isaksen" <oy****@webressurs.no> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
When I bind the dropdownlist-control to a datareader, it displays all the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of the
dropdownlist? I want the first choice in the dropdownlist to be "blank"
(no value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)


Jan 31 '06 #3
The only way to get it to display "Choose..." is to add it as Kim said,
but changing "" to "Choose...".

I would suggest using a label beside the dropdownlist.

Øyvind Isaksen wrote:
Yes, this inserted a blank in the top of the dropdownlist.
But, I only want the value to be blank (""), now the value AND text is
blank. Do you know how I get the text = "choose"...? (And still value = "")

Thanks!!
"Kim Quigley" <ki********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
I didn't test this, but I'm pretty sure this is what you have to do. After
the DataBind line of code, add:

Me.drpCompany.items.insert(0,"")

"Øyvind Isaksen" <oy****@webressurs.no> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
When I bind the dropdownlist-control to a datareader, it displays all the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of the
dropdownlist? I want the first choice in the dropdownlist to be "blank"
(no value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)



Jan 31 '06 #4
Ed
You can *manually* add the first item to your DropDownList, then
programmatically add more listitems.

Ex:
DropDownList.Items.Add(blah - data from your db)

--
Cheers,
Ed Chavez
A bona fide Microsoft drone

"Øyvind Isaksen" <oy****@webressurs.no> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
When I bind the dropdownlist-control to a datareader, it displays all the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of the
dropdownlist? I want the first choice in the dropdownlist to be "blank"
(no value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)

Feb 1 '06 #5
I got the solution, this works:
me.myDromDovn.Items.Insert(0, new ListItem("Choose ...", string.Empty))

Øyvind Isaksen :)


"Zamdrist" <za******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
The only way to get it to display "Choose..." is to add it as Kim said,
but changing "" to "Choose...".

I would suggest using a label beside the dropdownlist.

Øyvind Isaksen wrote:
Yes, this inserted a blank in the top of the dropdownlist.
But, I only want the value to be blank (""), now the value AND text is
blank. Do you know how I get the text = "choose"...? (And still value =
"")

Thanks!!
"Kim Quigley" <ki********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
I didn't test this, but I'm pretty sure this is what you have to do.
After
the DataBind line of code, add:

Me.drpCompany.items.insert(0,"")

"Øyvind Isaksen" <oy****@webressurs.no> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
When I bind the dropdownlist-control to a datareader, it displays all
the
data (from the database) in the dropdownlist.

My question is:
How do I insert a "<option value="">Choose...</option>" in the top of
the
dropdownlist? I want the first choice in the dropdownlist to be "blank"
(no value), just display a text like "Choose"...
This is the code that bind the dropdownlist to the datareader:

cmd.Connection.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Me.drpCompany.DataSource = dr
Me.drpCompany.DataTextField = "company"
Me.drpCompany.DataValueField = "companyID"
Me.drpCompany.DataBind()
cmd.Connection.Close()
Thanks for all tips :)


Feb 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ganesh Kolappan via .NET 247 | last post by:
Hi I am trying to populate a <asp:dropdownlist> in a XSLT file withdatasource pointing to a C# codebehind file method which returnsa dataview. I am using XSLT extension object. But I am...
1
by: Marius | last post by:
Hi all, I need an asp:dropdownlist on a webform that is databound to a dataset. This works fine and returns the data to populate my dropdownlist. In the DB I only have valid data, but I need a...
1
by: Harry | last post by:
Hi, Just seeing if anyone can help me with a problem I am having with drop down lists. - I have a asp:dropdownlist that gets its values from a database. - The user then selects a value then...
2
by: amessimon | last post by:
I need to display a drop down list which holds up to 250 listitems. I'd like to create this programmatically rather than have to hardcode it into the page. For example <asp:DropDownList...
1
by: Urmal Patel via .NET 247 | last post by:
I have problem with asp:Dropdownlist. I have a dropdownlist control in Page1.aspx and I want to assign value and Text to dropdown list form Page2.aspx from java script function. I am able to assign...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
1
by: Xuanly ly via .NET 247 | last post by:
asp:dropdownlist always display infront of everything and I can't make it display behind HELP HELP help!!!. <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1"...
2
by: HH | last post by:
Hi, I have a dropdown list that is datafilled via a SQL table. The text part is always unique. (A list of countries) Each country is assigned one of three numbers. (This being the 'value' of...
1
by: Miguel Dias Moura | last post by:
Hello, I have two questions concerning Asp:DropDownList 1. How to fill a DropDownList from runtime and set its default item? 2. How do use a DropDownList in each datagrid record? All...
2
by: John Smith | last post by:
I have this DataGrid: <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateColumn HeaderText="SM"> <ItemTemplate> <asp:Label id="Label2" runat="server"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.