Want first choice in databound dropdownlist to be empty regardless of the actual databound list

Last post 03-03-2008 9:45 AM by vinz. 3 replies.

Sort Posts:

  • Want first choice in databound dropdownlist to be empty regardless of the actual databound list

    03-03-2008, 9:20 AM
    • Member
      67 point Member
    • finittz
    • Member since 01-08-2008, 6:57 PM
    • Posts 119

    I have a data bound (MS Access) drop down list. I want nothing to be selected or shown as the first item, so that the user can select any item from the list. This is because there is a select index changed event linked to this drop down list.

    Right now since the first item in the data bound list is "company 1" so if a user wants to select "company 1" and have the select index changed fire FOR "company 1" they have to select another company first then they have to select "company 1" so that the select index changed event uses the value of "company 1" in its function. Thanks.

     

    I'm using an AccessDataSource control for the databinding of a MS Access database to the dropdownlist.  

    Using Visual Studio 2005. Language: C#
  • Re: Want first choice in databound dropdownlist to be empty regardless of the actual databound list

    03-03-2008, 9:33 AM
    • All-Star
      86,764 point All-Star
    • ecbruck
    • Member since 12-30-2005, 7:39 PM
    • Des Moines, IA
    • Posts 9,209
    • Moderator
      TrustedFriends-MVPs

    Simply add an empty ListItem declaratively to your DropDownList and ensure that you have the AppendDataBoundItems property set to True. 

    <asp:dropdownlist id="DropDownList1" runat="server" appenddatabounditems="true">
    	<asp:listitem text="" value="" />
    </asp:dropdownlist>
    Thanks, Ed

    Microsoft MVP - ASP/ASP.NET

  • Re: Want first choice in databound dropdownlist to be empty regardless of the actual databound list

    03-03-2008, 9:42 AM
    • Member
      67 point Member
    • finittz
    • Member since 01-08-2008, 6:57 PM
    • Posts 119

     I tried that but the problem is that later on I add new items to the database and I databind the drop down list again. That is where the problem occurs because then with the appenddatabounditems=true the new items + old items get added to all the old items in the drop down list. It doesn't just refresh the drop down list like if appenddatabounditems=false.

    Using Visual Studio 2005. Language: C#
  • Re: Want first choice in databound dropdownlist to be empty regardless of the actual databound list

    03-03-2008, 9:45 AM
    Answer
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 3:47 PM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    finittz:

     I tried that but the problem is that later on I add new items to the database and I databind the drop down list again. That is where the problem occurs because then with the appenddatabounditems=true the new items + old items get added to all the old items in the drop down list. It doesn't just refresh the drop down list like if appenddatabounditems=false.

    Hi finittz,

    You need to Clear the DDL Items every time you bind it with a new Data so that it will not bind the Old with the New Value...

    DropDownList1.Items.Clear();

    //BIND YOUR GRID 

    "Code,Beer and Music ~ my way of being a programmer"

Page 1 of 1 (4 items)