Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Best Practice for Populating a DropDownList control

    Hello All,

    I'm building a web form in Visual Studio .Net 2003 and have a question about populating dropdownlist controls. I know that I can populate each ddl control by adding items in the "Items (Collection)" property, but is it "better" to build some lookup tables and populate them via data binding? I seem to find a ton of info about the datagrid and data binding when searching for dropdownlist control info and I'm wondering if that is what I should be doing instead of using the Items collection. Does it just depend on how the app uses the data from the ddl? My application simply has six ddl's and one submit button that will save the selected items from the dropdownlists to a sql table. Thanks in advance!

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dim CONN As New SqlConnection("connstr")
    CONN.Open()
    Dim CMD As New SqlCommand("select val_field, text_field from yourtable", CONN)
    Dim DR As SqlDataReader = CMD.ExecuteReader()
    ddlList.DataSource = DR
    ddlList.DataValueField = "val_field"
    ddlList.DataTextField = "text_field"
    ddlList.DataBind()
    ddlList.Items.Insert(0, "SELECT...")
    DR.Close()
    CONN.Close()
    Robert
    Gee! Web Tools
    Web Content Management / Internet Marketing modules including:
    Page Editor - Calendar Manager - News Editor - Contact Organizer - Mail Wizard


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •