Add non sqldatasource listitems to asp:dropdown linked to a sqldatasource

Posted on 2010-08-20
Last Modified: 2012-05-10
I have an asp:dropdown populated from a sqldatasource control and it works great.  However, I need to add 1 more listitem that is not pulled from the query to put in the dropdown but it does not show up.  How can I do this?
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsMember" DataTextField="MEMBER_SNAME" DataValueField="MEMBER_ID">
<asp:ListItem Text="All Members" Value="0" Selected="True"></asp:ListItem>
<asp:SqlDataSource ID="sdsMember" runat="server" ConnectionString="<%$ ConnectionStrings:DBSFL %>" SelectCommand="select MEMBER_SNAME, MEMBER_ID from MEMBER order by MEMBER_SNAME ASC"></asp:SqlDataSource>

Open in new window

Question by:rondre
  • 2
  • 2

Author Comment

ID: 33483473
In case it wasn't clear, the output on the page is all of the items from the select statement of the sqldatasource but the asp:listitem "All Members" does not show up - looking to see how this is done.  Thanks!
LVL 22

Accepted Solution

Om Prakash earned 500 total points
ID: 33483618
Add AppendDataBoundItems="true" to asp:DropDownList

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsMember" DataTextField="MEMBER_SNAME" DataValueField="MEMBER_ID" AppendDataBoundItems="true">
LVL 19

Expert Comment

ID: 33483655
Check it out....
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

    CodeBehind="Default.aspx.cs" Inherits="EETest._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


        Welcome to ASP.NET!



        To learn more about ASP.NET visit <a href="" title="ASP.NET Website"></a>.



        You can also find <a href=";clcid=0x409"

            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.


    <asp:DropDownList ID="People" runat="server"></asp:DropDownList>


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace EETest


    public partial class _Default : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)


            People.DataSource = GetPeople();


            People.PreRender += new EventHandler(People_PreRender);


        private void People_PreRender(object sender, EventArgs e)


            People.Items.Insert(0, new ListItem("Sharon"));


        private List<String> GetPeople()


            List<String> people = new List<string>();




            return people;




Open in new window

LVL 19

Expert Comment

ID: 33483734
om_prakash_p is right - sorry I didn't see you had a ListItem already there!

Author Closing Comment

ID: 33486149
thank you - that works perfect!

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
visual Basic Net vs c# net 8 56
Default parameter problem in C# 3 27
Check my code out(2) 1 35
Create XML 5 35
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

11 Experts available now in Live!

Get 1:1 Help Now