race2
01-07-2002, 12:01
Su ASP.NET:
Ho un ListBox() che popolo nel seguente modo:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'popolo la ListBox Categorie
Dim ID As Integer
Dim Cat As String
conn.Open()
Dim sql As String = "SELECT * FROM Categorie"
Dim comm As New OleDbCommand(sql, conn)
Dim read As OleDbDataReader = comm.ExecuteReader
While read.Read()
ID = read("Id")
lsbCat.Items.Add(read("Cat"))
End While
conn.Close()
End Sub
lsbCat.Items.Add(read("Cat")) questa e' la riga che uso per popolare, e fin qui mi funziona.
Poi voglio selezionare un Item e fare popolare un altra ListBox() con l'Item selezionato dalla prima, e faccio nel segiente modo:
Private Sub lsbCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsbCat.SelectedIndexChanged
'popolo la ListBox SubCategorie
Dim ID As Integer = lsbCat.SelectedItem.Value
Dim IDC As Integer
Dim IDS As Integer
Dim SubCat As String
conn.Open()
Dim sql As String = "SELECT * FROM SubCategorie WHERE IDC = " & ID & ""
Dim comm As New OleDbCommand(sql, conn)
Dim read As OleDbDataReader = comm.ExecuteReader
While read.Read()
IDS = read("Id")
IDC = read("IDC")
lsbSubCat.Items.Add(read("SubCat"))
End While
conn.Close()
End Sub
E qui non mi funziona ......!!!!!
al momento che seleziono un Item dalla prima ListBox() non mi si popola la seconda, vorrei popolare la seconda dato l'ID della prima,
come devo fare ???
Ho un ListBox() che popolo nel seguente modo:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'popolo la ListBox Categorie
Dim ID As Integer
Dim Cat As String
conn.Open()
Dim sql As String = "SELECT * FROM Categorie"
Dim comm As New OleDbCommand(sql, conn)
Dim read As OleDbDataReader = comm.ExecuteReader
While read.Read()
ID = read("Id")
lsbCat.Items.Add(read("Cat"))
End While
conn.Close()
End Sub
lsbCat.Items.Add(read("Cat")) questa e' la riga che uso per popolare, e fin qui mi funziona.
Poi voglio selezionare un Item e fare popolare un altra ListBox() con l'Item selezionato dalla prima, e faccio nel segiente modo:
Private Sub lsbCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lsbCat.SelectedIndexChanged
'popolo la ListBox SubCategorie
Dim ID As Integer = lsbCat.SelectedItem.Value
Dim IDC As Integer
Dim IDS As Integer
Dim SubCat As String
conn.Open()
Dim sql As String = "SELECT * FROM SubCategorie WHERE IDC = " & ID & ""
Dim comm As New OleDbCommand(sql, conn)
Dim read As OleDbDataReader = comm.ExecuteReader
While read.Read()
IDS = read("Id")
IDC = read("IDC")
lsbSubCat.Items.Add(read("SubCat"))
End While
conn.Close()
End Sub
E qui non mi funziona ......!!!!!
al momento che seleziono un Item dalla prima ListBox() non mi si popola la seconda, vorrei popolare la seconda dato l'ID della prima,
come devo fare ???