kevin bailey
kevin bailey

Reputation:

Databind() on gridview not working VB.net ASP.Net

I have a datatable with verified 10 rows named dtable. I attempt to bind it to my gridview and nothing shows up on my asp.net page. Why do these relatively simple few lines not populate my gridview?

    Dim con As SqlConnection = Nothing
    Dim dTable As DataTable
    Dim dataAdapter As SqlDataAdapter
    Dim sqlcmd As String
    .......
    dTable = New DataTable
    dataAdapter = New SqlDataAdapter(sqlcmd, con)
    dataAdapter.Fill(dTable)

    'DATATABLE at this point has 10 rows in it, I verified that at runtime

    gvUnitSystem.DataSource = dTable
    gvUnitSystem.DataBind()

End Sub

What am I doing wrong?

Upvotes: 1

Views: 9271

Answers (3)

tom
tom

Reputation: 1

You need to set the con (connection string).

Upvotes: 0

Mike Marshall
Mike Marshall

Reputation: 7850

This looks fine. Are you auto-populating columns or have you manually added columns in the designer? If it is the latter maybe none of the column fields match fields in your table.

Upvotes: 0

JaredPar
JaredPar

Reputation: 754745

Have you made sure that the GridView has AutoGenerateColumns set to true?

gvUnitSystem.AutoGenerateColumns = True

Upvotes: 3

Related Questions