Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 599
  • Last Modified:

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.
1 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now