Binding a Scalar Array to a DataGrid Demo

This demo illustrates binding a scalar array of integers to a DataGrid whose AutoGenerateColumns property is set to True (the default).


Item
1
1
2
3
5
8
13
21
34
55
89


Source Code
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim fib(10) As Integer
    Dim i as Integer
    
    fib(0) = 1
    fib(1) = 1
    
    For i = 2 To 10
        fib(i) = fib(i - 1) + fib(i - 2)
    Next

    Me.dgArrayAutoGenerate.DataSource = fib
    Me.dgArrayAutoGenerate.DataBind()
End Sub
</script>

<asp:DataGrid id="dgArrayAutoGenerate" runat="server"
       AutoGenerateColumns="True">
</asp:DataGrid>

[Return to the article...]