Binding an arraylist to a datagrid

D

David H.

I'm trying to bind an arraylist to a datagrid web control

The arraylist contains "mystates" objects with properties named "state" and "abbreviation.

I can set the grid's datasource to be the arraylist, but I am having trouble referencing the properties of each arraylist item by their name. For example, the grid doesn't like

<asp:boundcolumn datafield="state" /

Is there an easy way around this

Thanks
- David H.
 
A

Alessandro Zifiglio

use a datatable whereas to arraylist for this. I dont think the datagrids
allows this with arraylists, however i could easily be wrong.

David H. said:
I'm trying to bind an arraylist to a datagrid web control.

The arraylist contains "mystates" objects with properties named "state" and "abbreviation."

I can set the grid's datasource to be the arraylist, but I am having
trouble referencing the properties of each arraylist item by their name.
For example, the grid doesn't like:
 
T

Teemu Keiski

Hi,

how are you exactly trying to do that. In my test I had a Datagrid

<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="State" />
</Columns>
</asp:DataGrid>

I had a class MyState:

Public Class MyState
Private _abbreviation As String
Private _State As String
Public Sub New(ByVal abbreviation As String, ByVal state As String)
_abbreviation = abbreviation
_State = state
End Sub
Public ReadOnly Property Abbreviation() As String
Get
Return _abbreviation
End Get
End Property
Public ReadOnly Property State() As String
Get
Return _State
End Get
End Property
End Class

which was used with the grid:

Dim arrList As New ArrayList
arrList.Add(New MyState("A1", "1"))
arrList.Add(New MyState("A2", "2"))
arrList.Add(New MyState("A3", "3"))
DataGrid1.DataSource = arrList
DataGrid1.DataBind()

And it worked just fine.

Are you perhaps using C#? Have you make sure that it's not anything related
just to case-sensitivity, if you are?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist




I'm trying to bind an arraylist to a datagrid web control.

The arraylist contains "mystates" objects with properties named "state" and
"abbreviation."

I can set the grid's datasource to be the arraylist, but I am having trouble
referencing the properties of each arraylist item by their name. For
example, the grid doesn't like:

<asp:boundcolumn datafield="state" />

Is there an easy way around this?

Thanks!
- David H.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top