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">
                        <asp:TextBox ID="TextBox" Columns="5" Runat="Server" />
                        <asp:DropDownList Runat="server" ID="DropDown" />
                        <asp:Label ID="drugs" Runat="server" Text='<%# DataBinder.Eval(Container.) %>' />

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


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


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

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!


Wednesday, May 11, 2005

*  Recent Topics

*  Fog Creek Home