如何将GridView当前页面转换为DataTable?
答案 0 :(得分:1)
你可以尝试这个(未经测试和不完整):
Dim tbl As New DataTable
For Each col As DataControlField In MyGrid.Columns
tbl.Columns.Add(New DataColumn(col.HeaderText))
Next
For Each row As GridViewRow In MyGrid.Rows
Dim params As New List(Of Object)
For Each cell As TableCell In row.Cells
Dim cellText As String = String.Empty
For Each ctrl As Control In cell.Controls
If TypeOf ctrl Is Label Then
cellText = DirectCast(ctrl, Label).Text
Exit For
ElseIf TypeOf ctrl Is TextBox Then
cellText = DirectCast(ctrl, TextBox).Text
Exit For
'to be continued....'
End If
Next
params.Add(cellText)
Next
tbl.Rows.Add(params.ToArray)
Next