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