Non sono molto esperto quindi mi scuso per le eventuali banalità o imprecisioni.
Devo popolare una GridView mediante una SqlDatasource dinamica (la WHERE è costruita in base ai valori inseriti in due textbox) e, successivamente, devo poter modificare i dati visualizzati nella gridview.
Il codice associato al click del pulsante "CERCA" è il seguente:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strsql As String
strsql = "SELECT * FROM [XSS-Sistemi3]"
If (TextBox2.Text <> "" Or TextBox8.Text <> "") Then
strsql = strsql & " WHERE "
If TextBox2.Text <> "" Then
If TextBox8.Text <> "" Then
strsql = ""
Else
strsql = strsql & " ([Hostname] like @hostname + '%') ORDER BY hostname"
End If
Else
strsql = strsql & " ([IP] like @IP + '%') ORDER BY hostname"
End If
Else
strsql = strsql & " ORDER BY hostname"
End If
SqlDataSource5.SelectCommand = strsql
End Sub
La visualizzazione e il filtro funzionano correttamente ma, dopo aver visualizzato i dati, se premo il CommanField "modifica" della GridView, la GridView sparisce.
Ho provato con una sola textbox (quindi con una WHERE statica nella query) e funziona tutto.
Grazie
Modificato da Punky il 19 novembre 2008 16.21 -