Home All Groups Group Topic Archive Search About
Author
18 Apr 2006 9:05 AM
Frederik Vanderhaeghe
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:
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

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???

Fré

Author
18 Apr 2006 10:53 AM
Ken Tucker [MVP]
Hi,

        You cant add items to the drop down list that is bound to a
datasource.  I would load the names into a datatable.  You can add Selecteer
een type to the datatable.  Then bind the datatable to the drop downlist.

Ken
--------------
Show quoteHide quote
"Frederik Vanderhaeghe" <frederikvanderhae***@gmail.com> wrote in message
news:%238hTNdsYGHA.4652@TK2MSFTNGP04.phx.gbl...
> 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:
> 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
>
> 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???
>
> Fré
>
Author
18 Apr 2006 11:35 AM
Frederik Vanderhaeghe
Hi,

Thank you, it works!

I have another problem. When I choose an item from the dropdownlist, an i
press search, the selected item changes into the first index. How can I
resolve this?

Fré

Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:u5$BrZtYGHA.508@TK2MSFTNGP02.phx.gbl...
> Hi,
>
>        You cant add items to the drop down list that is bound to a
> datasource.  I would load the names into a datatable.  You can add
> Selecteer een type to the datatable.  Then bind the datatable to the drop
> downlist.
>
> Ken
> --------------
> "Frederik Vanderhaeghe" <frederikvanderhae***@gmail.com> wrote in message
> news:%238hTNdsYGHA.4652@TK2MSFTNGP04.phx.gbl...
>> 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:
>> 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
>>
>> 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???
>>
>> Fré
>>
>
>