0

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.

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

The DataList is a bit more flexable in that case take a look at the RepeatColumns property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.