Populate a Datalist from a dataset

nkwk

Newcomer
Joined
Mar 11, 2004
Messages
13
I have problems with populating a datalist from my dataset. When I try it with a datagrid, everything seems to work fine but the datalist wont populate.

I have a wizard created connection, adapter and dataset.

The code:

Visual Basic:
    Private Sub BindList()
        SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM mailinglist WHERE Firstname = 'nick'"
        SqlDataAdapter1.Fill(DataSet11, "mailinglist")
        DataList1.DataSource = DataSet11
        DataList1.DataMember = "mailinglist"
        DataList1.DataBind()
    End Sub

Then calling it from the page load:
Visual Basic:
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindList()
        Label5.Text = SqlDataAdapter1.SelectCommand.CommandText
    End Sub
 
Shall be working... however some minor glitch

nkwk said:
I have problems with populating a datalist from my dataset. When I try it with a datagrid, everything seems to work fine but the datalist wont populate.

I have a wizard created connection, adapter and dataset.

The code:

Visual Basic:
Private Sub BindList()
SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM mailinglist WHERE Firstname = 'nick'"
SqlDataAdapter1.Fill(DataSet11, "mailinglist")
DataList1.DataSource = DataSet11
DataList1.DataMember = "mailinglist"
DataList1.DataBind()
End Sub

Then calling it from the page load:
Visual Basic:
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindList()
Label5.Text = SqlDataAdapter1.SelectCommand.CommandText
End Sub
Is your connection opened ?
I recommend verifying postback in the form load

if( Not IsPostBack )
... ... ...
End If

Well... it seems that everything is perfect. Make sure all your table are full. It might be a problem of filling.

Give me news.
 
Yeh sorry I removed that to make it less complicated.

it reads:

Visual Basic:
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            BindList()
        End If
        Label5.Text = SqlDataAdapter1.SelectCommand.CommandText
    End Sub
 
Please take a look at this

Did you check your DataTable to make sure all your commands fill your table correctly ?

I didn't work very often with DataList but I worked a lot with DataGrid. And I know that they are a little more harder to "control" than other simpler control (eg. TextBox ).
 
Are there any generated items in the datalist? If not then your datatable is empty. If the items are generated but they're empty, then you have a binding problem...
 
Back
Top