gridview上的Databind()无法使用VB.net ASP.Net

时间:2022-06-29 13:10:19

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?

我有一个数据表,经验证的10行名为dtable。我尝试将它绑定到我的gridview,并且我的asp.net页面上没有显示任何内容。为什么这些相对简单的几行不会填充我的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?

我究竟做错了什么?

3 个解决方案

#1


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

您确定GridView的AutoGenerateColumns设置为true吗?

gvUnitSystem.AutoGenerateColumns = True

#2


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.

看起来很好。您是自动填充列还是在设计器中手动添加了列?如果是后者,则列字段中没有一个匹配表中的字段。

#3


You need to set the con (connection string).

您需要设置con(连接字符串)。

#1


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

您确定GridView的AutoGenerateColumns设置为true吗?

gvUnitSystem.AutoGenerateColumns = True

#2


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.

看起来很好。您是自动填充列还是在设计器中手动添加了列?如果是后者,则列字段中没有一个匹配表中的字段。

#3


You need to set the con (connection string).

您需要设置con(连接字符串)。