473,405 Members | 2,415 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,405 software developers and data experts.

Insert item into dropdown

I am trying to insert an item into a dropdown which is bound to an
sqldatasource. Nothing happens when I place the following code in page load
and render event. Is the datasource overriding my insert or am I doing
something wrong

Dim lstitemcompany As New ListItem

lstitemcompany.Text = "Select a company"

lstitemcompany.Value = ""

drpCompanies.Items.Insert(0, lstitemcompany)
Jul 7 '06 #1
1 1621
do the insert in the DataBound event handler:

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
ddl.Items.Insert(0, new ListItem("text", "value"));
}
Chris wrote:
I am trying to insert an item into a dropdown which is bound to an
sqldatasource. Nothing happens when I place the following code in page load
and render event. Is the datasource overriding my insert or am I doing
something wrong

Dim lstitemcompany As New ListItem

lstitemcompany.Text = "Select a company"

lstitemcompany.Value = ""

drpCompanies.Items.Insert(0, lstitemcompany)
Jul 7 '06 #2

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

Similar topics

3
by: Jon | last post by:
I am using cascading dropdowns, where one dropdown determines the data in the next, etc... If a dropdown has only one item in it, the SelectedIndexChanged event is never fired, even if you click...
0
by: Tim::.. | last post by:
Can someone please help! I'm trying to write an insert statement for a complex datagrid! The database consists of the following data structure! ..tblContent PageID PK ModDate Description...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
2
by: David | last post by:
Hi, I have an asp page which runs an update into our mysql database. The only problem I have is that a user selects a customer from a dropdown (this is database fed), and I require the selected...
2
by: JackieW | last post by:
I have a drop down menu that I need to insert two distinct pieces of information with one choice. I need to insert a Category Number into column A and a Category Name into column B at the same time....
5
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the...
2
by: SunnySnow29 | last post by:
Hi, I have a 2 drop down lists in C# populated with data from a SQL 2005 db. When a new item of data is inserted the second list must update to reflect the change (the first drop down list will...
0
by: Ed Dror | last post by:
Hi there, I'm using Wisual Studio 2005 Pro with SQL server 2005 Dev on XP SP2 I have two tables Generic Item table (GN_ID) PK Color Table (Color_ID) PK and GN_ID FK very simple one to many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.