Binding local array values to a local gridview in VB.NET

Posted on 2008-11-06
Last Modified: 2009-07-29
If I have a local array with multiple columns in a VB code-behind page, how can I bind those data to a gridview on the aspx page?  Im used to binding a returned dataset to a gridview.
Question by:Stovetop
    1 Comment
    LVL 2

    Accepted Solution

    One way to bind an array to a gridview is to make a class out of the array.
    For example if you have an array with 3 columns make a class similar to the one below
    Class MyArray
       private mCol1;
     property mCol1 as String
            return mCol1   end Get
      Set(byVal Value as String)
        mCol1 = Value
    End Property
    Then Decalare the array of your class type
    dim lparray[] as MyArray
    Then in the code
     DataGrid1.DataSource = lparray
    dim gs as datagridtablestyle
    dim gc as datagridtextboxcolumn

     gs.MappingName = lparray.GetType.Name
    gc = New DataGridTextBoxColumn
    gc.MappingName = "Col1"
    'gc.HeaderText = "Col1"
    'gc.Alignment = HorizontalAlignment.Left
    'gc.Width = 125
    ' gc.TextBox.MaxLength = 20
    ' gc.TextBox.CharacterCasing = CharacterCasing.Upper

    ' gs.GridColumnStyles.Add(gc)
    ' DataGrid1.TableStyles.Add(gs)
    Hope this helps.  Dont know if it will work in ASP but it does work with VB.NET


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now