創建一個數據表,然後填充它創建表爲f ollows:
Private Function CreateDataSource() As DataTable
'creates the columns for the datatable
Dim dt As New DataTable 'create new datatable
'add appropriate columns to the table
Dim colImage As New DataColumn("Field1", GetType(Boolean))
colImage.DefaultValue = bShowExtraInfo
dt.Columns.Add(colImage)
dt.Columns.Add("Field2", GetType(String))
Return dt 'return the table
End Function
,然後用它在你的代碼如下所示:
Dim dt As DataTable = CreateDataSource() 'create the data table
Dim dr As DataRow
For Each x In y 'cycle through x and add to table
dr("Field1") = tableAvalue
dr("Field2") = tableBvalue
dt.Rows.Add(dr)
End If
Next
gvEverything.DataSource = dt
gvEverything.DataBind()
你使用像實體框架的東西嗎?如果是這樣,有一些非常簡單的解決方案。否則,您可以從您的數據中手動創建一個數據表。 – yougotiger