views:

205

answers:

2

Hi,

I have dropdownlist control where item lists are coming from database

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource2" DataTextField="semester" 
        DataValueField="semester">
    </asp:DropDownList>

But I want to add at the beginning 1 list item more "ALL" .. How can I add this one .

Thanks !

+4  A: 

To add a new list item to the DropDownList, in the Properties window, click on the ellipses in the Items property. Add a new list item with Text "ALL" & Value -1.

Or you can add the list item by adding this markup to the DropDownList:

<asp:DropDownList ID="categories" runat="server" ...>
    <asp:ListItem Value="-1">
       ALL
    </asp:ListItem>         
</asp:DropDownList>

Set the DropDownList's AppendDataBoundItems=True

DOK
+1 for AppendDataBoundItems, I didn't know that property.
Canavar
Yeah, omitting that could really mystify you, eh?
DOK
A: 

With Items.Insert method you can add an item at a specific index :

DropDownList1.Items.Insert(0, new ListItem("ALL", "ALL"));
Canavar