473,408 Members | 1,821 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,408 software developers and data experts.

DataBound dropdownlist + extra Item

Hi guys

I've got a dropdownlist which is being databound to an sqldatareader at
runtime. I want to add an extra Item to the list, not from the database.

I know I can do this with

ddl1.Items.Add(new ListItem("text", "value"));

works fine. However, if I put this above my DataBinding code, it doesn't
appear. After it it appears at the end of the list fine.

Question is, how do I databind AND get this item to the top of my list? It's
an ALL option y'see.

Cheers for any help!
Dan
Nov 19 '05 #1
4 1623
ddlLocation.DataSource = Line.GetBrandingLocations

ddlLocation.DataValueField = "BrandingLocationID"

ddlLocation.DataTextField = "BrandingLocation"

ddlLocation.DataBind()

'the following line inserts at position 0

ddlLocation.Items.Insert(0, "(Select)")

"dhnriverside" <da*@musoswire.com> wrote in message
news:37**********************************@microsof t.com...
Hi guys

I've got a dropdownlist which is being databound to an sqldatareader at
runtime. I want to add an extra Item to the list, not from the database.

I know I can do this with

ddl1.Items.Add(new ListItem("text", "value"));

works fine. However, if I put this above my DataBinding code, it doesn't
appear. After it it appears at the end of the list fine.

Question is, how do I databind AND get this item to the top of my list?
It's
an ALL option y'see.

Cheers for any help!
Dan

Nov 19 '05 #2
Or

ddlLocation.Items.Insert(0, New ListItem("(Select)", value)
Nov 19 '05 #3
Thanks SImon, worked great.
Dan

"Simon Hazelton" wrote:
ddlLocation.DataSource = Line.GetBrandingLocations

ddlLocation.DataValueField = "BrandingLocationID"

ddlLocation.DataTextField = "BrandingLocation"

ddlLocation.DataBind()

'the following line inserts at position 0

ddlLocation.Items.Insert(0, "(Select)")

"dhnriverside" <da*@musoswire.com> wrote in message
news:37**********************************@microsof t.com...
Hi guys

I've got a dropdownlist which is being databound to an sqldatareader at
runtime. I want to add an extra Item to the list, not from the database.

I know I can do this with

ddl1.Items.Add(new ListItem("text", "value"));

works fine. However, if I put this above my DataBinding code, it doesn't
appear. After it it appears at the end of the list fine.

Question is, how do I databind AND get this item to the top of my list?
It's
an ALL option y'see.

Cheers for any help!
Dan


Nov 19 '05 #4
Dan,

Do the databinding first and then call

ddl1.Items.Insert(0, new ListItem("text", "value"));

Eliyahu

"dhnriverside" <da*@musoswire.com> wrote in message
news:37**********************************@microsof t.com...
Hi guys

I've got a dropdownlist which is being databound to an sqldatareader at
runtime. I want to add an extra Item to the list, not from the database.

I know I can do this with

ddl1.Items.Add(new ListItem("text", "value"));

works fine. However, if I put this above my DataBinding code, it doesn't
appear. After it it appears at the end of the list fine.

Question is, how do I databind AND get this item to the top of my list? It's an ALL option y'see.

Cheers for any help!
Dan

Nov 19 '05 #5

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

Similar topics

18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
6
by: VB Programmer | last post by:
I have an itemtemplate in a datagrid. I'm trying to set it's value based on data. Having no trouble with the textbox. But, how do I do the same thing for a dropdownlist???? <ItemTemplate>...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
1
by: IMB | last post by:
I'm using VS2005 and am working with a ASP.NET 2.0 web site and I'm coding in VB.NET. I understand that I can add an item to a databound dropdownlist and make it the default selection using the...
1
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
2
by: Cirene | last post by:
In my databound datagrid i have a databound dropdownlist, like this: <asp:DropDownList ID="ddlAvail0" runat="server" SelectedValue='<%# Bind("AvailMon") %>'> <asp:ListItem></asp:ListItem>...
5
by: Cirene | last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query with a UNION. But I can't find the example....
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.