Home All Groups Group Topic Archive Search About

dropdownlist not filling up?



Author
18 Apr 2006 10:50 AM
Joris De Groote
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

Author
18 Apr 2006 10:56 AM
Evertjan.
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)
Author
18 Apr 2006 12:55 PM
Bob Barrows [MVP]
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.

AddThis Social Bookmark Button