locked
Default item at the top of a Drop Down List RRS feed

  • Question

  • User694418659 posted

    Hi all,

    I have this code in a page which pulls drop down list items from a Access mdb:

    <asp:DropDownList id="DropDownList1" runat="server" DataSourceID="AccessDataSource1" DataTextField="Category_1" DataValueField="Category_1" CssClass="TextBox">

    </asp:DropDownList>

    Is there anything I can add to this line (or anywhere else) which will appear as the default option at the top of the list eg "---Select---"?
    What's happening at the moment is that when the page loads, the first item from the drop down list in the mdb is being automatically used by the code above to return a whole bunch of records. 

    Mart

    Friday, May 17, 2019 11:58 AM

Answers

  • User-943250815 posted

    Set AppendDataBoundItens and add "Select" as ListItem

    <asp:DropDownList id="DropDownList1" runat="server" AppendDataBoundItems="True" DataSourceID="AccessDataSource1" DataTextField="Category_1" DataValueField="Category_1" CssClass="TextBox">
    <asp:ListItem>Select</asp:ListItem>
    </asp:DropDownList>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 17, 2019 12:08 PM

All replies

  • User-943250815 posted

    Set AppendDataBoundItens and add "Select" as ListItem

    <asp:DropDownList id="DropDownList1" runat="server" AppendDataBoundItems="True" DataSourceID="AccessDataSource1" DataTextField="Category_1" DataValueField="Category_1" CssClass="TextBox">
    <asp:ListItem>Select</asp:ListItem>
    </asp:DropDownList>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 17, 2019 12:08 PM
  • User694418659 posted

    Aha! Thanks. :-)

    Friday, May 17, 2019 12:21 PM