Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Databind Arraylist to datagrid...

I am trying to bind an arraylist to a datagrid, but I am having difficulties...

If i do a 'naked' datagrid it works, but I want to use a template column a bit like this

<asp:TemplateColumn HeaderText="Item">
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox" Columns="5" Runat="Server" />
                        <asp:DropDownList Runat="server" ID="DropDown" />
                 
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="drugs" Runat="server" Text='<%# DataBinder.Eval(Container.) %>' />
                    </ItemTemplate>
                </asp:TemplateColumn>

what magic do I put in the databinder.eval bit of my datagrid?

or am i going about this in the wrong way?

relevent google terms accepted :D

thanks

Aidan
Tuesday, May 10, 2005

<%# Container.DataItem.MyPropertyName %>

Where MyPropertyName is the name of a property on the object that is in the ArrayList.

If you're using C#, I believe you have to explicitly cast Container.DataItem to the correct type first.

Jeff Mastry
Tuesday, May 10, 2005

Thanks

                    <ItemTemplate>
                        <asp:Label ID="drugs" Runat="server" Text='<%# Container.dataitem %>' />
                    </ItemTemplate>

works. The things in the arraylist are just strings.

Now I am SURE i tried that as my first guess and it threw it back at me! Sometimes I hate programming :p

Typical thing where you struggle with a problem for 2hrs at the end of a day, and solve it in the morning as you get your first cup of tea!


    

Aidan
Wednesday, May 11, 2005

*  Recent Topics

*  Fog Creek Home