all groups > asp.net webcontrols > january 2004 >
You're in the

asp.net webcontrols

group:

Binding an arraylist to a datagrid


Binding an arraylist to a datagrid David H.
1/28/2004 9:36:05 AM
asp.net webcontrols:
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
Re: Binding an arraylist to a datagrid Alessandro Zifiglio
1/29/2004 7:09:42 PM
use a datatable whereas to arraylist for this. I dont think the datagrids
allows this with arraylists, however i could easily be wrong.

[quoted text, click to view]
trouble referencing the properties of each arraylist item by their name.
For example, the grid doesn't like:
[quoted text, click to view]

Re: Binding an arraylist to a datagrid Teemu Keiski
1/31/2004 4:41:07 PM
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




[quoted text, click to view]
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.

Re: Binding an arraylist to a datagrid Alessandro Zifiglio
1/31/2004 5:14:02 PM
Thanks for pointing that out Teemu, in fact i was easily wrong ;P
http://support.microsoft.com/default.aspx?kbid=316302

[quoted text, click to view]

AddThis Social Bookmark Button