Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick VB.NET question

  • 18-08-2004 01:27PM
    #1
    Registered Users, Registered Users 2 Posts: 937 ✭✭✭


    Hi, I have a drop down box that gets filled with information from a database for a search, i want to be able to add a value "All", I've tried
    <asp:ListItem Value="All" Selected="True">All</asp:ListItem>
    
    but that doesnt seem to show the all, i reckon its getting overwritten when I
    dropDown1.datasource=cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    dropDown1.DataValueField = "DBcolName"
    dropDown1.databind
    dropDown1.visible="true"
    
    bind the column to the drop down, any suggestions.
    Any help much appreciated.
    dave


Comments

  • Registered Users, Registered Users 2 Posts: 1,432 ✭✭✭Merrion


    Add "All" to the data set you are binding to.


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    add it in where??? in the database??? (thats not really an option)


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    You have two options, one is add it to the dropdown manually after the databind in your code behind class..

    //This is C#, so convert to VB.Net
    dropDown.DataBind();
    oItem = new ListItem("All", "");
    dropDown.Items.Insert(0, oItem);

    or bind to a datatable within a dataset instead of datareader. Populate the datatable using a SqlDataAdapter and then manually add the "All" entry to the datatabe. You will probably want to actually bind to a DataView which uses the DataTable as its source and add a field to sort on so All comes to the top.


  • Registered Users, Registered Users 2 Posts: 937 ✭✭✭Diddy Kong


    cheers, worked like a dream...


Advertisement