Error when binding 2D Array to Gridview
I want to bind a multidimensional array to gridview, but it display the following error when running "Gridview1.DataBind()
"
"Array was not a one-dimensiona开发者_如何学Gol array."
The following is my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CreateArray()
End Sub
Private Sub CreateArray()
Dim Array(4, 3) As String
Array(0, 0) = "ABC"
Array(1, 0) = "DEF"
Array(2, 2) = "GHJ"
Array(1, 3) = "XVZ"
Gridview1.DataSource = Array
Gridview1.DataBind()
End Sub
Is there any mistake in my code ? Thanks,
Joe
Use a DataTable instead of the MultiDimmensional array. These will bind nicely to a GridView (or other data controls).
http://www.issociate.de/board/goto/880762/Binding_Multidimensional_Array_to_DataGrid.html
You can't bind a 2D Array
to a Gridview
. It should be either a Single Dimensional array
, a DataTable
, or a Collection
to bind data to a GridView.
精彩评论