473,785 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dropdownlist

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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é

Apr 18 '06 #1
12 1689
Can you add the standard value (Selecteer een type) in the dataset(table)
with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uO******** ******@TK2MSFTN GP05.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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é

Apr 18 '06 #2
Maybe because your code says:
ddlDocType.Sele ctedIndex = 0
????
"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Can you add the standard value (Selecteer een type) in the dataset(table)
with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uO******** ******@TK2MSFTN GP05.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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é



Apr 18 '06 #3
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Can you add the standard value (Selecteer een type) in the dataset(table)
with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uO******** ******@TK2MSFTN GP05.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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é


Apr 18 '06 #4
Yes, but that is because the selected item when loaded must be the one at
index 0. But when changed it mus be the chosen one.

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** **********@TK2M SFTNGP02.phx.gb l...
Maybe because your code says:
ddlDocType.Sele ctedIndex = 0
????
"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Can you add the standard value (Selecteer een type) in the
dataset(table) with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in
message news:uO******** ******@TK2MSFTN GP05.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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é




Apr 18 '06 #5
Hi,

Have you set the property EnableViewState to true on the drop down list
control? If you have what other code have you got, there must be something
setting it back to 0.

Regards
Wozza

"Frederik Vanderhaeghe" wrote:
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Can you add the standard value (Selecteer een type) in the dataset(table)
with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uO******** ******@TK2MSFTN GP05.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_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

Try

connectie.Open( )

da.Fill(ds, "doctype")

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

Catch ex As Exception

Finally

connectie.Close ()

ddlDocType.Item s.Insert(0, "Selecteer een type")

ddlDocType.Sele ctedIndex = 0

End Try

End If

lblZoeken.Visib le = False

dtgZoekResultat en.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é



Apr 18 '06 #6
It is standard set to true, i didn't change it. All my code is:
Dim connectie As New SqlClient.SqlCo nnection("Serve r=" + getsqlserver() +
";Initial Catalog=" + getsqlcatalog() + ";Trusted_Conne ction=True")

Dim strSQL As String

Dim ds As New DataSet

Dim whereSQL As String = "where "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

InlezenConfig()

End If

Dim strsqlDocType As String = "select distinct type from
TBL_Bestanden_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

da.Fill(ds, "doctype")

Dim row As DataRow

row = ds.Tables("doct ype").NewRow

row("Type") = "Selecteer een type"

ds.Tables("doct ype").Rows.Add( row)

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

ddlDocType.Sele ctedIndex = ds.Tables("doct ype").Rows.Coun t - 1

lblZoeken.Visib le = False

dtgZoekResultat en.Visible = True

End Sub

'Knop Velden leegmaken => alle zoekvelden leegmaken of niets geselecteerd

Private Sub btnreset_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnreset.Click

Me.txtdocbedrag .Text = ""

Me.txtdocdatumV an.Text = ""

Me.txtdocdatumT ot.Text = ""

Me.txtdocnr.Tex t = ""

Me.txtklantnaam .Text = ""

Me.txtklantnr.T ext = ""

End Sub

Private Sub btnzoeken_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnzoeken.Click

Dim i As New Integer

'documentnummer ingevuld

If Not (txtdocnr.Text = "") Then

whereSQL += "docnr like '" & txtdocnr.Text & "' and "

End If

'klantnummer ingevuld

If Not (txtklantnr.Tex t = "") Then

whereSQL += "klnr like '" & txtklantnr.Text & "' and "

End If

'klantnaam ingevuld

If Not (txtklantnaam.T ext = "") Then

Dim klantnaam As String = Trim(txtklantna am.Text)

Do While (InStr(klantnaa m, " ") > 0)

klantnaam = Microsoft.Visua lBasic.Left(kla ntnaam, InStr(klantnaam ,
InStr(klantnaam , " ") - 1)) + _

Microsoft.Visua lBasic.Right(kl antnaam, InStr(klantnaam , Len(klantnaam) -
InStr(klantnaam , " ")))

Loop

If Microsoft.Visua lBasic.Right(kl antnaam, 1).Equals("*") Then

If Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "%' or klnaam like '%" &
txtklantnaam.Te xt & "%' and "

Else

whereSQL += "klnaam like '" & klantnaam & "%' or klnaam like '" &
txtklantnaam.Te xt & "%' and "

End If

ElseIf Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "' or klnaam like '%" &
txtklantnaam.Te xt & "' and "

Else

whereSQL += "klnaam like '" & txtklantnaam.Te xt & "' or klnaam like '" &
klantnaam & "' and "

End If

End If

'document datum ingevuld

If Not (txtdocdatumTot .Text = "") Then

If Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) between '" & txtdocdatumVan. Text &
"' and '" & CDate(txtdocdat umTot.Text) & "' and "

Else

lblDatum.ForeCo lor = System.Drawing. Color.Red

End If

ElseIf Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) = '" & CDate(txtdocdat umVan.Text) &
"' and "

End If

'document bedrag ingevuld

If Not (txtdocbedrag.T ext = "") Then

Select Case ddlBedrag.Selec tedIndex

Case 0

Case 1

strSQL += "bedrag > '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 2

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 3

strSQL += "bedrag < '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 4

strSQL += "bedrag <= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 5

strSQL += "bedrag = '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 6

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and bedrag <
'" & Double.Parse(tx tBedragTot.Text ) & "' and "

End Select

End If

'documenttype ingevuld

i = 0

'While (i < ds.Tables("doct ype").Rows.Coun t)

'If (ddlDocType.Sel ectedIndex = i) Then

whereSQL += "type like '" & ddlDocType.Sele ctedValue & "' and "

'i = ds.Tables("doct ype").Rows.Coun t

'End If

'i += 1

'End While

'laatste " and " van de string knippen

whereSQL = Microsoft.Visua lBasic.Left(whe reSQL, whereSQL.Length - 5)

'strSQL maken

strSQL = "select Id, docnr, klnr, klnaam, datum, bedrag, type from
TBL_Bestanden_Z oeken " & whereSQL & " order by docnr"

If ((txtdocnr.Text = "") And (txtklantnr.Tex t = "") And (txtklantnaam.T ext =
"") And (txtdocdatumVan .Text = "") And (txtdocdatumTot .Text = "") And
(txtdocbedrag.T ext = "") And (txtBedragTot.T ext = "") And Not
(ddlDocType.Sel ectedIndex = 0)) Then

lblZoeken.Visib le = True

strSQL = ""

dtgZoekResultat en.Visible = False

Else

'dataset opvullen

Dim da2 As New SqlClient.SqlDa taAdapter(strSQ L, connectie)

da2.Fill(ds, "bestanden" )

If (ds.Tables("bes tanden").Rows.C ount <> 0) Then

dtgZoekResultat en.DataSource = ds.Tables("best anden").Default View

DataBind()

Else

lblZoeken.Text = "Er is niets gevonden"

lblZoeken.Visib le = True

dtgZoekResultat en.Visible = False

End If

End If

End Sub

Private Sub dtgZoekResultat en_PageIndexCha nged(ByVal source As
System.Object, ByVal e As
System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
dtgZoekResultat en.PageIndexCha nged

dtgZoekResultat en.CurrentPageI ndex = e.NewPageIndex

dtgZoekResultat en.DataBind()

End Sub

End Class

"Wozza" <Wo***@discussi ons.microsoft.c om> wrote in message
news:EC******** *************** ***********@mic rosoft.com...
Hi,

Have you set the property EnableViewState to true on the drop down list
control? If you have what other code have you got, there must be something
setting it back to 0.

Regards
Wozza

"Frederik Vanderhaeghe" wrote:
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
> Can you add the standard value (Selecteer een type) in the
> dataset(table)
> with Rows.InsertAt maybe and then databind the dropdown?
>
> "Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in
> message
> news:uO******** ******@TK2MSFTN GP05.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_Z oeken"
>>
>> Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)
>>
>> Try
>>
>> connectie.Open( )
>>
>> da.Fill(ds, "doctype")
>>
>> ddlDocType.Data Source = ds.Tables("doct ype")
>>
>> ddlDocType.Data Bind()
>>
>> Catch ex As Exception
>>
>> Finally
>>
>> connectie.Close ()
>>
>> ddlDocType.Item s.Insert(0, "Selecteer een type")
>>
>> ddlDocType.Sele ctedIndex = 0
>>
>> End Try
>>
>> End If
>>
>> lblZoeken.Visib le = False
>>
>> dtgZoekResultat en.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é
>>
>>
>>
>
>


Apr 18 '06 #7
You change the selectedIndex yourself:
ddlDocType.Sele ctedIndex = ds.Tables("doct ype").Rows.Coun t - 1
"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:OV******** ******@TK2MSFTN GP04.phx.gbl...
It is standard set to true, i didn't change it. All my code is:
Dim connectie As New SqlClient.SqlCo nnection("Serve r=" + getsqlserver() +
";Initial Catalog=" + getsqlcatalog() + ";Trusted_Conne ction=True")

Dim strSQL As String

Dim ds As New DataSet

Dim whereSQL As String = "where "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

InlezenConfig()

End If

Dim strsqlDocType As String = "select distinct type from
TBL_Bestanden_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

da.Fill(ds, "doctype")

Dim row As DataRow

row = ds.Tables("doct ype").NewRow

row("Type") = "Selecteer een type"

ds.Tables("doct ype").Rows.Add( row)

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

ddlDocType.Sele ctedIndex = ds.Tables("doct ype").Rows.Coun t - 1

lblZoeken.Visib le = False

dtgZoekResultat en.Visible = True

End Sub

'Knop Velden leegmaken => alle zoekvelden leegmaken of niets geselecteerd

Private Sub btnreset_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnreset.Click

Me.txtdocbedrag .Text = ""

Me.txtdocdatumV an.Text = ""

Me.txtdocdatumT ot.Text = ""

Me.txtdocnr.Tex t = ""

Me.txtklantnaam .Text = ""

Me.txtklantnr.T ext = ""

End Sub

Private Sub btnzoeken_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnzoeken.Click

Dim i As New Integer

'documentnummer ingevuld

If Not (txtdocnr.Text = "") Then

whereSQL += "docnr like '" & txtdocnr.Text & "' and "

End If

'klantnummer ingevuld

If Not (txtklantnr.Tex t = "") Then

whereSQL += "klnr like '" & txtklantnr.Text & "' and "

End If

'klantnaam ingevuld

If Not (txtklantnaam.T ext = "") Then

Dim klantnaam As String = Trim(txtklantna am.Text)

Do While (InStr(klantnaa m, " ") > 0)

klantnaam = Microsoft.Visua lBasic.Left(kla ntnaam, InStr(klantnaam ,
InStr(klantnaam , " ") - 1)) + _

Microsoft.Visua lBasic.Right(kl antnaam, InStr(klantnaam , Len(klantnaam) -
InStr(klantnaam , " ")))

Loop

If Microsoft.Visua lBasic.Right(kl antnaam, 1).Equals("*") Then

If Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "%' or klnaam like '%" &
txtklantnaam.Te xt & "%' and "

Else

whereSQL += "klnaam like '" & klantnaam & "%' or klnaam like '" &
txtklantnaam.Te xt & "%' and "

End If

ElseIf Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "' or klnaam like '%" &
txtklantnaam.Te xt & "' and "

Else

whereSQL += "klnaam like '" & txtklantnaam.Te xt & "' or klnaam like '" &
klantnaam & "' and "

End If

End If

'document datum ingevuld

If Not (txtdocdatumTot .Text = "") Then

If Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) between '" & txtdocdatumVan. Text
& "' and '" & CDate(txtdocdat umTot.Text) & "' and "

Else

lblDatum.ForeCo lor = System.Drawing. Color.Red

End If

ElseIf Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) = '" & CDate(txtdocdat umVan.Text)
& "' and "

End If

'document bedrag ingevuld

If Not (txtdocbedrag.T ext = "") Then

Select Case ddlBedrag.Selec tedIndex

Case 0

Case 1

strSQL += "bedrag > '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 2

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 3

strSQL += "bedrag < '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 4

strSQL += "bedrag <= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 5

strSQL += "bedrag = '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 6

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and bedrag
< '" & Double.Parse(tx tBedragTot.Text ) & "' and "

End Select

End If

'documenttype ingevuld

i = 0

'While (i < ds.Tables("doct ype").Rows.Coun t)

'If (ddlDocType.Sel ectedIndex = i) Then

whereSQL += "type like '" & ddlDocType.Sele ctedValue & "' and "

'i = ds.Tables("doct ype").Rows.Coun t

'End If

'i += 1

'End While

'laatste " and " van de string knippen

whereSQL = Microsoft.Visua lBasic.Left(whe reSQL, whereSQL.Length - 5)

'strSQL maken

strSQL = "select Id, docnr, klnr, klnaam, datum, bedrag, type from
TBL_Bestanden_Z oeken " & whereSQL & " order by docnr"

If ((txtdocnr.Text = "") And (txtklantnr.Tex t = "") And (txtklantnaam.T ext
= "") And (txtdocdatumVan .Text = "") And (txtdocdatumTot .Text = "") And
(txtdocbedrag.T ext = "") And (txtBedragTot.T ext = "") And Not
(ddlDocType.Sel ectedIndex = 0)) Then

lblZoeken.Visib le = True

strSQL = ""

dtgZoekResultat en.Visible = False

Else

'dataset opvullen

Dim da2 As New SqlClient.SqlDa taAdapter(strSQ L, connectie)

da2.Fill(ds, "bestanden" )

If (ds.Tables("bes tanden").Rows.C ount <> 0) Then

dtgZoekResultat en.DataSource = ds.Tables("best anden").Default View

DataBind()

Else

lblZoeken.Text = "Er is niets gevonden"

lblZoeken.Visib le = True

dtgZoekResultat en.Visible = False

End If

End If

End Sub

Private Sub dtgZoekResultat en_PageIndexCha nged(ByVal source As
System.Object, ByVal e As
System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
dtgZoekResultat en.PageIndexCha nged

dtgZoekResultat en.CurrentPageI ndex = e.NewPageIndex

dtgZoekResultat en.DataBind()

End Sub

End Class

"Wozza" <Wo***@discussi ons.microsoft.c om> wrote in message
news:EC******** *************** ***********@mic rosoft.com...
Hi,

Have you set the property EnableViewState to true on the drop down list
control? If you have what other code have you got, there must be
something
setting it back to 0.

Regards
Wozza

"Frederik Vanderhaeghe" wrote:
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
> Can you add the standard value (Selecteer een type) in the
> dataset(table)
> with Rows.InsertAt maybe and then databind the dropdown?
>
> "Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in
> message
> news:uO******** ******@TK2MSFTN GP05.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_Z oeken"
>>
>> Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)
>>
>> Try
>>
>> connectie.Open( )
>>
>> da.Fill(ds, "doctype")
>>
>> ddlDocType.Data Source = ds.Tables("doct ype")
>>
>> ddlDocType.Data Bind()
>>
>> Catch ex As Exception
>>
>> Finally
>>
>> connectie.Close ()
>>
>> ddlDocType.Item s.Insert(0, "Selecteer een type")
>>
>> ddlDocType.Sele ctedIndex = 0
>>
>> End Try
>>
>> End If
>>
>> lblZoeken.Visib le = False
>>
>> dtgZoekResultat en.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é
>>
>>
>>
>
>


Apr 18 '06 #8
But after a postback the page will be loaded again.
So the code will run also....

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:Ox******** ******@TK2MSFTN GP04.phx.gbl...
Yes, but that is because the selected item when loaded must be the one at
index 0. But when changed it mus be the chosen one.

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** **********@TK2M SFTNGP02.phx.gb l...
Maybe because your code says:
ddlDocType.Sele ctedIndex = 0
????
"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:uR******** ******@TK2MSFTN GP05.phx.gbl...
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Can you add the standard value (Selecteer een type) in the
dataset(table) with Rows.InsertAt maybe and then databind the dropdown?

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in
message news:uO******** ******@TK2MSFTN GP05.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_Z oeken"
>
> Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)
>
> Try
>
> connectie.Open( )
>
> da.Fill(ds, "doctype")
>
> ddlDocType.Data Source = ds.Tables("doct ype")
>
> ddlDocType.Data Bind()
>
> Catch ex As Exception
>
> Finally
>
> connectie.Close ()
>
> ddlDocType.Item s.Insert(0, "Selecteer een type")
>
> ddlDocType.Sele ctedIndex = 0
>
> End Try
>
> End If
>
> lblZoeken.Visib le = False
>
> dtgZoekResultat en.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é
>
>
>



Apr 18 '06 #9
Try this:

Dim connectie As New SqlClient.SqlCo nnection("Serve r=" + getsqlserver() +
";Initial Catalog=" + getsqlcatalog() + ";Trusted_Conne ction=True")

Dim strSQL As String
Dim ds As New DataSet
Dim whereSQL As String = "where "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

InlezenConfig()

Dim strsqlDocType As String = "select distinct type from
TBL_Bestanden_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

da.Fill(ds, "doctype")

Dim row As DataRow

row = ds.Tables("doct ype").NewRow

row("Type") = "Selecteer een type"

ds.Tables("doct ype").Rows.Add( row)

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

ddlDocType.Sele ctedIndex = ds.Tables("doct ype").Rows.Coun t - 1

lblZoeken.Visib le = False

dtgZoekResultat en.Visible = True

End If

End Sub

"Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in message
news:OV******** ******@TK2MSFTN GP04.phx.gbl...
It is standard set to true, i didn't change it. All my code is:
Dim connectie As New SqlClient.SqlCo nnection("Serve r=" + getsqlserver() +
";Initial Catalog=" + getsqlcatalog() + ";Trusted_Conne ction=True")

Dim strSQL As String

Dim ds As New DataSet

Dim whereSQL As String = "where "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

InlezenConfig()

End If

Dim strsqlDocType As String = "select distinct type from
TBL_Bestanden_Z oeken"

Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)

da.Fill(ds, "doctype")

Dim row As DataRow

row = ds.Tables("doct ype").NewRow

row("Type") = "Selecteer een type"

ds.Tables("doct ype").Rows.Add( row)

ddlDocType.Data Source = ds.Tables("doct ype")

ddlDocType.Data Bind()

ddlDocType.Sele ctedIndex = ds.Tables("doct ype").Rows.Coun t - 1

lblZoeken.Visib le = False

dtgZoekResultat en.Visible = True

End Sub

'Knop Velden leegmaken => alle zoekvelden leegmaken of niets geselecteerd

Private Sub btnreset_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnreset.Click

Me.txtdocbedrag .Text = ""

Me.txtdocdatumV an.Text = ""

Me.txtdocdatumT ot.Text = ""

Me.txtdocnr.Tex t = ""

Me.txtklantnaam .Text = ""

Me.txtklantnr.T ext = ""

End Sub

Private Sub btnzoeken_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnzoeken.Click

Dim i As New Integer

'documentnummer ingevuld

If Not (txtdocnr.Text = "") Then

whereSQL += "docnr like '" & txtdocnr.Text & "' and "

End If

'klantnummer ingevuld

If Not (txtklantnr.Tex t = "") Then

whereSQL += "klnr like '" & txtklantnr.Text & "' and "

End If

'klantnaam ingevuld

If Not (txtklantnaam.T ext = "") Then

Dim klantnaam As String = Trim(txtklantna am.Text)

Do While (InStr(klantnaa m, " ") > 0)

klantnaam = Microsoft.Visua lBasic.Left(kla ntnaam, InStr(klantnaam ,
InStr(klantnaam , " ") - 1)) + _

Microsoft.Visua lBasic.Right(kl antnaam, InStr(klantnaam , Len(klantnaam) -
InStr(klantnaam , " ")))

Loop

If Microsoft.Visua lBasic.Right(kl antnaam, 1).Equals("*") Then

If Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "%' or klnaam like '%" &
txtklantnaam.Te xt & "%' and "

Else

whereSQL += "klnaam like '" & klantnaam & "%' or klnaam like '" &
txtklantnaam.Te xt & "%' and "

End If

ElseIf Microsoft.Visua lBasic.Left(kla ntnaam, 1).Equals("*") Then

whereSQL += "klnaam like '%" & klantnaam & "' or klnaam like '%" &
txtklantnaam.Te xt & "' and "

Else

whereSQL += "klnaam like '" & txtklantnaam.Te xt & "' or klnaam like '" &
klantnaam & "' and "

End If

End If

'document datum ingevuld

If Not (txtdocdatumTot .Text = "") Then

If Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) between '" & txtdocdatumVan. Text
& "' and '" & CDate(txtdocdat umTot.Text) & "' and "

Else

lblDatum.ForeCo lor = System.Drawing. Color.Red

End If

ElseIf Not (txtdocdatumVan .Text = "") Then

whereSQL += "convert(dateti me,datum,101) = '" & CDate(txtdocdat umVan.Text)
& "' and "

End If

'document bedrag ingevuld

If Not (txtdocbedrag.T ext = "") Then

Select Case ddlBedrag.Selec tedIndex

Case 0

Case 1

strSQL += "bedrag > '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 2

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 3

strSQL += "bedrag < '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 4

strSQL += "bedrag <= '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 5

strSQL += "bedrag = '" & Double.Parse(tx tdocbedrag.Text ) & "' and "

Case 6

strSQL += "bedrag >= '" & Double.Parse(tx tdocbedrag.Text ) & "' and bedrag
< '" & Double.Parse(tx tBedragTot.Text ) & "' and "

End Select

End If

'documenttype ingevuld

i = 0

'While (i < ds.Tables("doct ype").Rows.Coun t)

'If (ddlDocType.Sel ectedIndex = i) Then

whereSQL += "type like '" & ddlDocType.Sele ctedValue & "' and "

'i = ds.Tables("doct ype").Rows.Coun t

'End If

'i += 1

'End While

'laatste " and " van de string knippen

whereSQL = Microsoft.Visua lBasic.Left(whe reSQL, whereSQL.Length - 5)

'strSQL maken

strSQL = "select Id, docnr, klnr, klnaam, datum, bedrag, type from
TBL_Bestanden_Z oeken " & whereSQL & " order by docnr"

If ((txtdocnr.Text = "") And (txtklantnr.Tex t = "") And (txtklantnaam.T ext
= "") And (txtdocdatumVan .Text = "") And (txtdocdatumTot .Text = "") And
(txtdocbedrag.T ext = "") And (txtBedragTot.T ext = "") And Not
(ddlDocType.Sel ectedIndex = 0)) Then

lblZoeken.Visib le = True

strSQL = ""

dtgZoekResultat en.Visible = False

Else

'dataset opvullen

Dim da2 As New SqlClient.SqlDa taAdapter(strSQ L, connectie)

da2.Fill(ds, "bestanden" )

If (ds.Tables("bes tanden").Rows.C ount <> 0) Then

dtgZoekResultat en.DataSource = ds.Tables("best anden").Default View

DataBind()

Else

lblZoeken.Text = "Er is niets gevonden"

lblZoeken.Visib le = True

dtgZoekResultat en.Visible = False

End If

End If

End Sub

Private Sub dtgZoekResultat en_PageIndexCha nged(ByVal source As
System.Object, ByVal e As
System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
dtgZoekResultat en.PageIndexCha nged

dtgZoekResultat en.CurrentPageI ndex = e.NewPageIndex

dtgZoekResultat en.DataBind()

End Sub

End Class

"Wozza" <Wo***@discussi ons.microsoft.c om> wrote in message
news:EC******** *************** ***********@mic rosoft.com...
Hi,

Have you set the property EnableViewState to true on the drop down list
control? If you have what other code have you got, there must be
something
setting it back to 0.

Regards
Wozza

"Frederik Vanderhaeghe" wrote:
I already fixed the problem, but i have another :-(

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é

"Pipo" <Pa****@Mayo.co m> wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
> Can you add the standard value (Selecteer een type) in the
> dataset(table)
> with Rows.InsertAt maybe and then databind the dropdown?
>
> "Frederik Vanderhaeghe" <fr************ ******@gmail.co m> wrote in
> message
> news:uO******** ******@TK2MSFTN GP05.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_Z oeken"
>>
>> Dim da As New SqlClient.SqlDa taAdapter(strsq lDocType, connectie)
>>
>> Try
>>
>> connectie.Open( )
>>
>> da.Fill(ds, "doctype")
>>
>> ddlDocType.Data Source = ds.Tables("doct ype")
>>
>> ddlDocType.Data Bind()
>>
>> Catch ex As Exception
>>
>> Finally
>>
>> connectie.Close ()
>>
>> ddlDocType.Item s.Insert(0, "Selecteer een type")
>>
>> ddlDocType.Sele ctedIndex = 0
>>
>> End Try
>>
>> End If
>>
>> lblZoeken.Visib le = False
>>
>> dtgZoekResultat en.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é
>>
>>
>>
>
>


Apr 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2808
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
4
5483
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
2
17034
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
2
2394
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to populate the second dropdown, as its not bale to find the specified control, even though the dropdownlist with the specified name exists in the datagrid. my .aspx page code goes like this
10
5325
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a certain control by id, but I want to find all controls of a certain type (DropDownList in this case). Is there an easier way than to get a control count of the page, loop through all controls on that page, examine their type and, if they're a...
15
3132
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
1
4660
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3501
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
1
4940
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item, the following error occurs: 'ddlAssignedTo' has a SelectedValue which is invalid because it...
0
1941
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for almost everything. but it whas made in Visual Studio 7 and i converted it to 2005. in version 7 it works almost perfect but in 2005 i am having some errors. becase all the code i am using is very long i am trying to post the nesecery code only if...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.