Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Quick VB.NET question

Options
  • 18-08-2004 1:27pm
    #1
    Registered Users 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 Posts: 1,421 ✭✭✭Merrion


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


  • Registered Users Posts: 937 ✭✭✭Diddy Kong


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


  • Registered Users 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 Posts: 937 ✭✭✭Diddy Kong


    cheers, worked like a dream...


Advertisement