473,497 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DropDownList: possible to add new rows after the DataSource has been set?


Hi everyone,

I'm have a DropDownList that populates itself from a DataTable. Is
there some way to "append" additional rows after the datasource has been
attached? For example, I'd like to bind my DropDown, then add an extra row
for a default entry that'll appear no matter what data is retrieved.

I've looked around but didn't see an Add() method I could use. Is what
I'm asking possible, or is it the case you're out of luck after binding your
datasource? Thanks for the help.

-Jim
Nov 19 '05 #1
4 1344
What you want is easy.. and there definately is an Add() method.

With this you add an item which will end up in the bottom of the list:
DropDownList1.Items.Add("Select an item")

Wíth this you will insert an item in the top (index 0):
DropDownList1.Items.Insert(0,"Select an item")

OR...if you need to create an item that also has a value, since most Items
you have in a dropdownbox should return a value instead of a text.
DropDownList1.Items.Insert(0, New ListItem("Select an item", "VALUE"))

Questions?

Best regards/
Lars Netzel
"Jim Bancroft" <as******@nowhere.com> skrev i meddelandet
news:uM**************@TK2MSFTNGP14.phx.gbl...

Hi everyone,

I'm have a DropDownList that populates itself from a DataTable. Is
there some way to "append" additional rows after the datasource has been
attached? For example, I'd like to bind my DropDown, then add an extra
row for a default entry that'll appear no matter what data is retrieved.

I've looked around but didn't see an Add() method I could use. Is what
I'm asking possible, or is it the case you're out of luck after binding
your datasource? Thanks for the help.

-Jim

Nov 19 '05 #2
Jim,

In situations like yours I add rows to the DataTable after filling in with
data from the database. Then I bind the list to the table in a regular way.

Eliyahu

"Jim Bancroft" <as******@nowhere.com> wrote in message
news:uM**************@TK2MSFTNGP14.phx.gbl...

Hi everyone,

I'm have a DropDownList that populates itself from a DataTable. Is
there some way to "append" additional rows after the datasource has been
attached? For example, I'd like to bind my DropDown, then add an extra row for a default entry that'll appear no matter what data is retrieved.

I've looked around but didn't see an Add() method I could use. Is what I'm asking possible, or is it the case you're out of luck after binding your datasource? Thanks for the help.

-Jim

Nov 19 '05 #3
Thanks....leave it to me to forget about the Items collection ;)

-Jim
Nov 19 '05 #4
Check out this code snippet to know how to add datagrid item to datagrid
without datasource
http://www.extremeexperts.com/Net/Co...aGridItem.aspx

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"Jim Bancroft" <as******@nowhere.com> wrote in message
news:uf**************@tk2msftngp13.phx.gbl...
Thanks....leave it to me to forget about the Items collection ;)

-Jim

Nov 19 '05 #5

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

Similar topics

0
1641
by: DotNetJunkies User | last post by:
Hie, I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,label,..) and then want to create handler so that if i change the select item in the dop downlist...
12
2755
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
16974
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
0
4778
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
1
2348
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
9
330
by: samuelberthelot | last post by:
Hi, I'm having a bad time trying to bind a dpl in a datagrid. Here are my SQL tables: {PersonId, PersonName, PersonGroupId} {PersonGroupId, PersonGroupName} The first column in my grid shows...
12
1661
by: Frederik Vanderhaeghe | last post by:
Hi, I have a dropdownlist that contains should contain several values from the database, I fill it up in de page_load() with this code: If Not Page.IsPostBack Then InlezenConfig() Dim...
2
9935
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
3
2353
by: RPhlb | last post by:
This is my first post, so excuse me if I don't get this right the first time. I have an issue where when I use DropDownList I only get the first, or "SelectedValue" back when I update a GridView...
0
6991
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
7160
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
7196
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
5456
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
4897
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
4583
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
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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.