How to create a three column table in ASP.Net Repeater How to create a three column table in ASP.Net Repeater asp.net asp.net

How to create a three column table in ASP.Net Repeater


Repeater is not the ideal control to do that. If you're using .NET 3.5 you should use ListView instead. Here's an example that does what you're asking for.

<asp:ListView ID="myListView" runat="server"    DataSourceID="YOURDATASOURCE" GroupItemCount="3">   <LayoutTemplate>      <table>         <tr>            <td>               <table border="0" cellpadding="5">                  <asp:PlaceHolder runat="server" ID="groupPlaceHolder"></asp:PlaceHolder>               </table>            </td>         </tr>      </table>   </LayoutTemplate>   <GroupTemplate>      <tr>         <asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>      </tr>   </GroupTemplate>   <ItemTemplate>      <td>         <%# Eval("FullName") %>      </td>   </ItemTemplate></asp:ListView>


It's better to use a DataList control intstead as it has the interesting properties RepeatColumns and RepeatDirection.


Much simpler than all the examples listed here; You don't need to use a list view or do anything in the code behind.

  <asp:Repeater ID="ExampleRepeater" runat="server" >    <HeaderTemplate>        <table>            <tr>                <th>   Column 1                </th>                <th>   Column 2                </th>                <th>   Column 3                </th>            </tr>    </HeaderTemplate>    <ItemTemplate>        <tr>            <td>                <asp:LinkButton ID="RemoveButton" runat="server" Text='Remove' CommandName="Remove"                    CommandArgument='<%# Eval("ID") %>' CausesValidation="false"></asp:LinkButton>            </td>            <td>                <asp:LinkButton ID="EditLink" runat="server" Text='<%# Eval("Name")  %>'                    CommandName="Edit" CommandArgument='<%# Eval("ID") %>' CausesValidation="false"></asp:LinkButton>            </td>            <td>                <asp:Label ID="CommentTextBox" runat="server" Text='<%# Eval("Comment")  %>' />            </td>        </tr>    </ItemTemplate>    <FooterTemplate>        </table>    </FooterTemplate></asp:Repeater>