开发者

tabular data in asp.net webform

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开发者_如何学JAVA 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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜