dropdownlist not filling up?

Discussion in 'ASP General' started by Joris De Groote, Apr 18, 2006.

  1. Hi,

    I have a dropdownlist that contains should contain several values from the
    database, I fill it up in de page_load() with this code (at the end of the
    message)

    The code also adds a standard value, 'Selecteer een type' that should be
    added at the beginning of the list. The problem now is that when i start my
    application only the value 'Selecteer uw type' is in the dropdownlist, but
    the other values from the database should also be in it. How can i fix
    this???

    Thanks
    Joris


    ---Code---
    If Not Page.IsPostBack Then

    InlezenConfig()

    Dim strsqlDocType As String = "select distinct type from
    TBL_Bestanden_Zoeken"

    Dim da As New SqlClient.SqlDataAdapter(strsqlDocType, connectie)

    Try

    connectie.Open()

    da.Fill(ds, "doctype")

    ddlDocType.DataSource = ds.Tables("doctype")

    ddlDocType.DataBind()

    Catch ex As Exception

    Finally

    connectie.Close()

    ddlDocType.Items.Insert(0, "Selecteer een type")

    ddlDocType.SelectedIndex = 0

    End Try

    End If

    lblZoeken.Visible = False

    dtgZoekResultaten.Visible = True
     
    Joris De Groote, Apr 18, 2006
    #1
    1. Advertising

  2. Joris De Groote

    Evertjan. Guest

    Joris De Groote wrote on 18 apr 2006 in
    microsoft.public.inetserver.asp.general:

    > Dim strsqlDocType As String =


    This is not classic ASP, where this NG is about.

    Could be VB or asp.net, but those have other NG's

    Probeer het daar eens, Joris.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 18, 2006
    #2
    1. Advertising

  3. Joris De Groote wrote:
    > Hi,
    >
    > I have a dropdownlist that contains should contain several values
    > from the database, I fill it up in de page_load() with this code (at
    > the end of the message)


    There was no way for you to know it, but this is a classic asp newsgroup.
    ASP.Net is a different technology from classic ASP.
    While you may be lucky enough to find a dotnet-savvy person here who can
    answer your question, you can eliminate the luck factor by posting your
    question to a newsgroup where the dotnet-savvy people hang out. I suggest
    microsoft.public.dotnet.framework.aspnet.

    But read on:

    >
    > The code also adds a standard value, 'Selecteer een type' that should
    > be added at the beginning of the list. The problem now is that when i
    > start my application only the value 'Selecteer uw type' is in the
    > dropdownlist, but the other values from the database should also be
    > in it. How can i fix this???
    >

    You can't databind and manually add items to the list. It's one or the
    other. I suggest using a union query to add the "selecteer" option to the
    list that comes from the database:
    >
    > ---Code---
    > If Not Page.IsPostBack Then
    >
    > InlezenConfig()
    >
    > Dim strsqlDocType As String = "select distinct type from
    > TBL_Bestanden_Zoeken"
    >


    Change this statement to:

    Dim strsqlDocType As String = "select type from (" & _
    "select 0 as src,'Selecteer een type' as type union all " & _
    "select distinct 1,type from TBL_Bestanden_Zoeken) q" & _
    " order by src, type"


    HTH,
    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Apr 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    Error filling DropdownList

    tshad, Nov 11, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    748
    =?Utf-8?B?dGlta2xpbmc=?=
    Nov 12, 2005
  2. DavidC
    Replies:
    2
    Views:
    1,751
    DavidC
    Jan 18, 2010
  3. deepak kumar
    Replies:
    13
    Views:
    337
    deepak kumar
    Nov 5, 2004
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    122
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    119
Loading...

Share This Page