I want to bind a multidimensional array to gridview, but it display the following error when running "Gridview1.DataBind()"
"Array was not a one-dimensional 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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With