Solved

How to add item to databound combobox

Posted on 2007-11-16
4
2,061 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

729 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