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 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
Or
ddlLocation.Items.Insert(0, New ListItem("(Select)", value)
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
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>...
|
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....
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |