Solved

How to add item to databound combobox

Posted on 2007-11-16
4
2,039 Views
Last Modified: 2013-11-27
To figure this out, I am going to create a simple example of what I am actually doing. I have a combobox that is bound to a table. There is a display member and a value member for each item. For example, the combobox collection might look like this:

John Doe
Joan Doe
Juda Doe

Each of these values has the value member of 1, 2, and 3 respectively.
After the names, I want there to be an option "Add User". When the user selects it, I want it to be assigned the next highest number, which would be 4 in this example.

Does anyone know how to do this?
0
Comment
Question by:tiehaze
4 Comments
 
LVL 26

Accepted Solution

by:
Alan Warren earned 500 total points
ID: 20303935



I prefer to do it iusing my SQL with a union select, then handle the command argument on the postback when command argument is 0.

SELECT 0 AS 'MemberId', 'Add User' AS 'Member'
UNION ALL

SELECT DISTINCT ID AS 'MemberId', MemberName AS 'Member'
FROM            tblMembers

But you can also use the AppendDataBoundItems directive in your dropdownlist tag

<asp:DropDownList   ... AppendDatBoundItems="true">
<asp:ListItem Value="" Text="Add User" />
</asp:DropDownList>




hth

Alan ";0)

0
 
LVL 1

Expert Comment

by:Computer101
ID: 20520528
Forced accept.

Computer101
EE Admin
0
 

Expert Comment

by:harhsli_hbp
ID: 23275487
how can i acheive this same thing in C# for winforms. ??
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now