473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Append items to drop down lists

Hi, I have a drop down list ddlServers and in my data access layer I run a
stored procedure to populate it. I need to be able to append items to the
drop down list and don't know how to do this. Here is the code I use to bind
the data retrieved from the DAL to the field.

{
DAL GetAllServers = new DAL();
DataSet dsServerNames = GetAllServers.GetAllServers();
ddlServers.DataSource = dsServerNames;
ddlServers.DataTextField = "Server_Name";
ddlServers.DataValueField = "Server_Id";
ddlServers.DataBind();
ddlServers.Items.Insert(0,new ListItem("--Select a Server--",""));
Console.WriteLine();
}
Nov 17 '05 #1
2 1959
Samantha,

If I remember correctly, when you make a call to DataBind, it will
render the control, so your call to insert a new item will not be rendered.

Rather, you should take your data set, and add the item to that before
the call to DataBind. Either that, or populate the items manually from the
data set, adding your item at the end (or beginning).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Samantha Penhale" <Sa*************@discussions.microsoft.com> wrote in
message news:4B**********************************@microsof t.com...
Hi, I have a drop down list ddlServers and in my data access layer I run a
stored procedure to populate it. I need to be able to append items to the
drop down list and don't know how to do this. Here is the code I use to
bind
the data retrieved from the DAL to the field.

{
DAL GetAllServers = new DAL();
DataSet dsServerNames = GetAllServers.GetAllServers();
ddlServers.DataSource = dsServerNames;
ddlServers.DataTextField = "Server_Name";
ddlServers.DataValueField = "Server_Id";
ddlServers.DataBind();
ddlServers.Items.Insert(0,new ListItem("--Select a Server--",""));
Console.WriteLine();
}

Nov 17 '05 #2
Thank you so much for addressing this!
"Nicholas Paldino [.NET/C# MVP]" wrote:
Samantha,

If I remember correctly, when you make a call to DataBind, it will
render the control, so your call to insert a new item will not be rendered.

Rather, you should take your data set, and add the item to that before
the call to DataBind. Either that, or populate the items manually from the
data set, adding your item at the end (or beginning).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Samantha Penhale" <Sa*************@discussions.microsoft.com> wrote in
message news:4B**********************************@microsof t.com...
Hi, I have a drop down list ddlServers and in my data access layer I run a
stored procedure to populate it. I need to be able to append items to the
drop down list and don't know how to do this. Here is the code I use to
bind
the data retrieved from the DAL to the field.

{
DAL GetAllServers = new DAL();
DataSet dsServerNames = GetAllServers.GetAllServers();
ddlServers.DataSource = dsServerNames;
ddlServers.DataTextField = "Server_Name";
ddlServers.DataValueField = "Server_Id";
ddlServers.DataBind();
ddlServers.Items.Insert(0,new ListItem("--Select a Server--",""));
Console.WriteLine();
}


Nov 17 '05 #3

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

Similar topics

1
3475
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
3
7331
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
2
1898
by: coolsti | last post by:
I am not new to Javascript and have been working with it for years now. I have also written my own parent - child and parent - child - child drop down lists. But when I look at some web sites, I...
3
5853
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
0
7432
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...
1
7094
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
5677
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,...
1
5079
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...
0
4743
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...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.