DataList is not populating, while datagrid is..

evanheld

Newcomer
Joined
Nov 20, 2003
Messages
13
Location
Sarasota, FL
I am trying to populate a datalist so I can take advantage of the RepeatColumns() and RepeatDirection() functionality. After having problems getting it to populate, I dropped a datagrid on the form and assigned a datasource to it and called the databind() method using the same dataview object I am trying to use with the datalist. And it worked just fine! :mad:

Here is the code. This is all in the PageLoad() Sub.

Appreciate any suggestions:



If Not IsPostBack Then

Dim myUnit As Unit
Dim dt As New DataTable
Dim dr As DataRow
Dim i As Integer
Dim DS As New DataSet
Dim Data As New DataClass
DS = Data.QuerySQL("select FirstName, LastName from tblCustomer", "tblCustomer")

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

For i = 0 To DS.Tables("tblCustomer").Rows.Count - 1
dr = dt.NewRow
dr(0) = DS.Tables("tblCustomer").Rows(i).Item("FirstName")
dr(1) = DS.Tables("tblCustomer").Rows(i).Item("LastName")
dt.Rows.Add(dr)
Next
Dim dv As New DataView(dt)

DataList1.Style("Top") = 20
DataList1.Style("Left") = 20
DataList1.Height = myUnit.Pixel(200)
DataList1.Width = myUnit.Pixel(200)
DataList1.Visible = True

'this doesn't work (why not??!!)
DataList1.DataSource = dv
DataList1.DataBind()

'Datagrid - this works!! But I need to use a DataList
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End If
 
Last edited:
DataList has different requirements than DataGrid

First of all, I should have posted this question in the ASP.Net area. This is what I have found...

Although you can bind a DataSet to a DataGrid and it automatically creates the grid for you a DataList acts differently. You need to set up <ItemTemplate> in asp code to define the table/grid.

Here is a great article that helped me solve this problem. Cheers to CraigAtl from the http://www.asp.net forum for providing this link!

http://www.w3schools.com/aspnet/aspnet_datalist.asp
 
Back
Top