2FieldsInListBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm trying to insert 2 fields of same ROW in a ListBox.
Following is the code in VB I had done previously: It worked
pretty straight forward.
------------------------In VB-------------------
If (DataContact.EOF = True) Then Combo2.Text = "No Item"
Do While Not DataContact.EOF
Combo2.AddItem DataContact.Fields("Contact_Name_VC")
Combo2.AddItem
DataContact.Fields("Sub_Contact_Name_VC")
Combo2.ItemData(Combo2.NewIndex) =
DataContact.Fields("Contact_ID")
DataContact.MoveNext
Loop
'End If
'close the recordsrt
DataContact.Close
Set DataContact = Nothing
========================In VB.NET=========
Try

ContactMgrConnection.Open()

' Response.Write(strFeeMgrQuery)

ContactMgrDatareader =
ContactMgrCommand.ExecuteReader(CommandBehavior.CloseConnection)

ListBox1.DataSource = ContactMgrDatareader

ListBox1.DataValueField = "Contact_ID"

ListBox1.DataTextField = "Contact_Name_VC"

ListBox1.DataTextField = "Sub_Contact_Name_VC"

ListBox1.DataBind()

Catch myException As Exception
'I'm able to trap only Sub_contact_Elements not Contact_elements


========================================
But I'm unable to execute the same in vb.net.
Any feed backe will be a real help.
Thanks.
 
Hi,

Try something like this.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not Me.IsPostBack Then

BindDataToGrid()

End If

End Sub

Private Sub BindDataToGrid()

Dim strConn As String

Dim conn As OleDb.OleDbConnection

Dim cmdOrders As OleDb.OleDbCommand

Dim dr As OleDb.OleDbDataReader

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = C:\Northwind.mdb;"

conn = New OleDb.OleDbConnection(strConn)

cmdOrders = New OleDb.OleDbCommand("Select (FirstName + ' ' + LastName) as
name from Employees", conn)

conn.Open()

dr = cmdOrders.ExecuteReader(CommandBehavior.CloseConnection)

ListBox1.DataSource = dr

ListBox1.DataTextField = "name"

ListBox1.DataBind()

End Sub



Ken

--------------------

Hi,
I'm trying to insert 2 fields of same ROW in a ListBox.
Following is the code in VB I had done previously: It worked
pretty straight forward.
------------------------In VB-------------------
If (DataContact.EOF = True) Then Combo2.Text = "No Item"
Do While Not DataContact.EOF
Combo2.AddItem DataContact.Fields("Contact_Name_VC")
Combo2.AddItem
DataContact.Fields("Sub_Contact_Name_VC")
Combo2.ItemData(Combo2.NewIndex) =
DataContact.Fields("Contact_ID")
DataContact.MoveNext
Loop
'End If
'close the recordsrt
DataContact.Close
Set DataContact = Nothing
========================In VB.NET=========
Try

ContactMgrConnection.Open()

' Response.Write(strFeeMgrQuery)

ContactMgrDatareader =
ContactMgrCommand.ExecuteReader(CommandBehavior.CloseConnection)

ListBox1.DataSource = ContactMgrDatareader

ListBox1.DataValueField = "Contact_ID"

ListBox1.DataTextField = "Contact_Name_VC"

ListBox1.DataTextField = "Sub_Contact_Name_VC"

ListBox1.DataBind()

Catch myException As Exception
'I'm able to trap only Sub_contact_Elements not Contact_elements


========================================
But I'm unable to execute the same in vb.net.
Any feed backe will be a real help.
Thanks.
 
Hi,
I'm trying to get one below the other say Main Contact listed after sub
contact.
Not Main Contact+Sub Contact.
Do let me knwo how to go about extracting one field below another.

Thanks
 
Back
Top