mamunahmed
asked on
Listbox display member and tag data in vb.net
I want to display one field but tag to a different field in listbox control.
I know there are two properties of listbox control: DisplayMember and ValueMember.
But how can I use these to the following situation?
This is in a web application and the code behind is vb.net (Visual Studio 2008).
I am putting all data access codes in a class. Accordingly, I have a listbox control in one page.
The class name is DataAccess.vb.
Aspx page name is: default.aspx
default.aspx.vb
I have the following in the default.aspx
<td>
<asp:ListBox ID="lstStoreRoom" runat="server" Rows="1" SelectionMode="Multiple">< /asp:ListB ox>
</td>
In the DataAccess.vb I have the following:
Public Sub lstStoreroom(ByRef lstItemNo As ListBox) 'listview control of store room
Try
sqlConn = ConnectionManager.GetNewCo nnection()
Using sqlConn
Dim command As OracleCommand = New OracleCommand("SELECT STOREID, STORENAME " & _
"FROM STOREROOM ORDER BY STOREID", sqlConn)
sqlConn.Open()
Dim reader As OracleDataReader = command.ExecuteReader()
If reader.HasRows Then
Do While reader.Read()
lstItemNo.Items.Add(reader (1).ToStri ng) 'want to display the store name
'want to tag the storeid for the storename because storeid will be used database manipulation.
Loop
End If
reader.Close()
End Using
Finally
If Not (sqlConn Is Nothing) Then
sqlConn.Close()
End If
End Try
End Sub
Then in the page load event of default.aspx.vb, I was doing the following:
Dim obj As New DataAccess
obj.lstStoreroom(lstStoreR oom)
Can you help me how I can tag the StoreId in this case?
Thanks a ton in advance,
regards,
Mamun
I know there are two properties of listbox control: DisplayMember and ValueMember.
But how can I use these to the following situation?
This is in a web application and the code behind is vb.net (Visual Studio 2008).
I am putting all data access codes in a class. Accordingly, I have a listbox control in one page.
The class name is DataAccess.vb.
Aspx page name is: default.aspx
default.aspx.vb
I have the following in the default.aspx
<td>
<asp:ListBox ID="lstStoreRoom" runat="server" Rows="1" SelectionMode="Multiple"><
</td>
In the DataAccess.vb I have the following:
Public Sub lstStoreroom(ByRef lstItemNo As ListBox) 'listview control of store room
Try
sqlConn = ConnectionManager.GetNewCo
Using sqlConn
Dim command As OracleCommand = New OracleCommand("SELECT STOREID, STORENAME " & _
"FROM STOREROOM ORDER BY STOREID", sqlConn)
sqlConn.Open()
Dim reader As OracleDataReader = command.ExecuteReader()
If reader.HasRows Then
Do While reader.Read()
lstItemNo.Items.Add(reader
'want to tag the storeid for the storename because storeid will be used database manipulation.
Loop
End If
reader.Close()
End Using
Finally
If Not (sqlConn Is Nothing) Then
sqlConn.Close()
End If
End Try
End Sub
Then in the page load event of default.aspx.vb, I was doing the following:
Dim obj As New DataAccess
obj.lstStoreroom(lstStoreR
Can you help me how I can tag the StoreId in this case?
Thanks a ton in advance,
regards,
Mamun
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Regards,
Mamun