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

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.
StovetopAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knk53Commented:
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
    Get
        return mCol1   end Get
  Set(byVal Value as String)
    mCol1 = Value
endSet
End Property
EndClass
 
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.