race2
01-07-2002, 13:19
con ASP.NET:
per raccogliere 2 valori quali l'ID e il testo, con una ListBox() ho usato la classe "MyListItem"
Public Class MyListItem
Private m_id As Long
Private m_text As String
Public Overrides Function ToString() As String
Return m_text
End Function
Public Sub New(ByVal Text As String, ByVal Value As Long)
m_text = Text
m_id = Value
End Sub
Public Property Value() As Long
Get
Return m_id
End Get
Set(ByVal Value As Long)
m_id = Value
End Set
End Property
Public Property Text() As String
Get
Return m_text
End Get
Set(ByVal Value As String)
m_text = Value
End Set
End Property
End Class
in questo modo:
'popolo la ListBox Categorie
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()
lsbCat.Items.Add(New ListItem(read("Cat"), read("Id").ToString))
End While
conn.Close()
e raccolgo i dato in questo modo:
Dim Item As MyListItem = lsbCat.SelectedItem
Dim ID As Integer = Item.Value
Dim Categoria As String = Item.Text
ma se voglio gestire tre valori invece che due come posso fare???
i tre campi da gestire
ID = integer
Cat = string
IDC = integer
la mia tabella:
ID -- Cat -- IDC
per raccogliere 2 valori quali l'ID e il testo, con una ListBox() ho usato la classe "MyListItem"
Public Class MyListItem
Private m_id As Long
Private m_text As String
Public Overrides Function ToString() As String
Return m_text
End Function
Public Sub New(ByVal Text As String, ByVal Value As Long)
m_text = Text
m_id = Value
End Sub
Public Property Value() As Long
Get
Return m_id
End Get
Set(ByVal Value As Long)
m_id = Value
End Set
End Property
Public Property Text() As String
Get
Return m_text
End Get
Set(ByVal Value As String)
m_text = Value
End Set
End Property
End Class
in questo modo:
'popolo la ListBox Categorie
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()
lsbCat.Items.Add(New ListItem(read("Cat"), read("Id").ToString))
End While
conn.Close()
e raccolgo i dato in questo modo:
Dim Item As MyListItem = lsbCat.SelectedItem
Dim ID As Integer = Item.Value
Dim Categoria As String = Item.Text
ma se voglio gestire tre valori invece che due come posso fare???
i tre campi da gestire
ID = integer
Cat = string
IDC = integer
la mia tabella:
ID -- Cat -- IDC