Populate A ListBox From A DataSource….     

 

 

        'Create A Table *********************************************

        Dim dt As New DataTable()

        Dim dr As DataRow

 

        dt.Columns.Add(New DataColumn("vAge", GetType(Int32)))

        dt.Columns.Add(New DataColumn("LastName", GetType(String)))

        dt.Columns.Add(New DataColumn("FirstName", GetType(String)))

 

        Dim i As Integer

        For i = 0 To 8

            dr = dt.NewRow()

            dr("vAge") = i

            dr("LastName") = " My Last " & i.ToString()

            dr("FirstName") = " My First " & i.ToString

            dt.Rows.Add(dr)

        Next i

 

        '*************************************************************

 

        'Add a new column to the table.  The column is FullName,

        'the combination of the Last & First name fields

        Dim DynColumn As New DataColumn()

        With DynColumn

            .ColumnName = "FullName"

            .DataType = System.Type.GetType("System.String")

            .Expression = "LastName+' '+FirstName"

        End With

        'objDs.Tables(0).Columns.Add(DynColumn)

        dt.Columns.Add(DynColumn)

        '*******************************************************

 

        ListBox1.DataSource = dt

        ListBox1.DataTextField = "FullName"

        ListBox1.DataBind()