PDA

View Full Version : [ASP] raccogliere tre valori con una ListBox()


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

tas
01-07-2002, 20:02
Basta aggiungere alla classe:

Private m_idc As Integer
...
Public Property IDC() As Integer
Get
Return m_idc
End Get
Set(ByVal Value As Integer)
m_idc = Value
End Set
End Property

race2
01-07-2002, 22:58
Ma mi da errore:

lsbSubCat.Items.Add(New MyClass1(read("SubCat"), read("Id").ToString, read("IDC").ToString))

non bisogna aggiungere qualcosaltro???

tipo:

ByVal value2 As Integer..........???

Public Sub New(ByVal Text As String, ByVal Value As Long, ByVal value2 As Integer)

altrimenti mi dice di passargli solo 2 parametri.....

ma come ho fatto io non funziona!!!!!!

In ALLEGATO.. c'e' l'errore.....!!!!!!


la classe :

Public Class MyClass1

Private m_idc As Long
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, ByVal IDC As Long)
m_text = Text
m_id = Value
m_idc = IDC
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

Public Property IDC() As Long
Get
Return m_idc
End Get
Set(ByVal Value As Long)
m_idc = Value
End Set
End Property

End Class

tas
02-07-2002, 20:57
Il problema è tutto qui:

lsbSubCat.Items.Add(New MyClass1(read("SubCat"), read("Id").ToString, read("IDC").ToString))

VB si aspetta di trovare, come parametri, (string, long, long), mentre tu gli dai (string, string, string).

Ecco la soluzione:

lsbSubCat.Items.Add(New MyClass1(read("SubCat"), read("Id"), read("IDC")))

race2
03-07-2002, 00:48
OK provo e poi ti faccio sapere, grazie mille per ora, ciao!!

race2
03-07-2002, 16:39
Mi da errore!!!!!!!!!

guarda l'allegato......... --->