Asp.Net List DataBinding

Posts   
 
    
VbMan
User
Posts: 6
Joined: 28-Nov-2006
# Posted on: 28-Nov-2006 01:52:16   

I am trying to bind to a listbox. I am new to LLBLGen Pro and so far I like it. What I need help with is how to populate a Asp.Net listbox with the 'Company Name' and the ID. I only want to pull the columns from the database without all the other fields. Here is what I have so far: --Vb.Net Dim adapter As New DL.DatabaseSpecific.DataAccessAdapter Dim fields As New DL.HelperClasses.ResultsetFields(2) Dim GenCo As New DL.EntityClasses.GenCompanyEntity

    fields.DefineField(DL.GenCompanyFieldIndex.Id, 0, "ID")
    fields.DefineField(DL.GenCompanyFieldIndex.CompanyName, 1, "Company Name")

    Dim dbTble As New DataTable
    adapter = New DL.DatabaseSpecific.DataAccessAdapter
    adapter.FetchTypedList(fields, dbTble, Nothing)
    Me.lstCompanyNames.DataSource = dbTble
    Me.lstCompanyNames.DataTextField = dbTble.Columns(1).ToString
    Me.lstCompanyNames.DataValueField = dbTble.Columns(0).ToString
    Page.DataBind()

I want to ensure that I am using the most effecient code possible. Is this correct? It works but doesnt mean it is the fastest/scalable code. Thanx! ~Mann.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Nov-2006 02:20:38   

I don't see any problems. You don't need to declare a new instance of DL.DatabaseSpecific.DataAccessAdapter after you create dbTble. Other than that it looks good.

VbMan
User
Posts: 6
Joined: 28-Nov-2006
# Posted on: 29-Nov-2006 00:19:32   

Ahh yes.

I meant to declare it first and instantiate it when I needed it not prior. Thanx, I need to go fix some code now.

~VbMan