Solved

How to add item to databound combobox

Posted on 2007-11-16
4
2,033 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
Comment Utility



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
Comment Utility
Forced accept.

Computer101
EE Admin
0
 

Expert Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

772 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

15 Experts available now in Live!

Get 1:1 Help Now