开发者

tabular data in asp.net webform

开发者 https://www.devze.com 2022-12-13 06:39 出处:网络
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:

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

精彩评论

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