views:

32

answers:

1

I have an arraylist which I'd like to display in a tabular fashion, but instead of one item per row, I'd like to do it like this:


item1 | item 2 | item 3 | item 4|

item 5 | etc.

Is there a control for this to which I can easily bind my data, or will I need to build the HTML out dynamically like I would have done in classic asp?

I know the best answer is probably 'MVC' but humor me.

+2  A: 

You can use a Repeater or a DataList.

Here is an example with the repeater:

Code Behind

ArrayList list = 
   new ArrayList() { "item1", "item 2", "item 3", "item 4", "item 5", "etc"  };
rpt.DataSource = list;
rpt.DataBind();

Markup

<asp:Repeater runat="server" id="rpt">
  <HeaderTemplate>
      <table><tr>
  </HeaderTemplate>   
  <ItemTemplate>
      <td>         
         <%# Container.DataItem.ToString() %>
      </td>
  </ItemTemplate>
  <FooterTemplate>
      </tr></table>
  </FoooterTemplate>
</asp:Repeater>
Bob
nice, thanks. How would I set the # of items per row?
fieldingmellish
The `DataList` is a bit more flexable in that case take a look at the `RepeatColumns` property.
Bob
got it- works great. thanks.
fieldingmellish