What I would like to do is show the records I get in datatable in different HTML tables. The records in the datatable have 3 columns and I can have a max of 6 records.
The datatable I am getting from the database is as follows:
Name Age
-----------
XYZ 30
XY1 31
XY2 32
XY3 33
And I want to show the records in the following way:
Name Age Name Age
-----------------------
XYZ 30 XY1 31
Name Age Name Age
-----------------------
XY2 32 XY3 33
Total Strength of employees : 4
What I am currently doing is as follows (although this is not what I want, but have tried):
<asp:Repeater ID="RptNCode" runat="server" OnItemCommand="RptNcode_ItemCommand"
OnItemDataBound="RptNCode_ItemDataBound" >
<HeaderTemplate>
<tr style="background-color: #507CD1; color:
White; font-weight: bold; text-align: center; height: 20px">
<td style="color: White;">
Sr.No
</td>
<td style="color: White; text-align: left">
Name
</td>
<td style="color: White; text-align: right">
Age
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color: #ffffff; height: 20px; font-family: Arial">
<td align="left" style="font-size: 15;">
<asp:LinkButton ID="lnkNCode" ForeColor="#336699" runat="server" Text='<%# Eval("Name") %>'
CommandArgument='<%# Eval("Name") %>' CommandName="NCode"></asp:LinkButton>
</td>
<td align="center" style="font-size: 15; text-align: right;">
<%# Eval("Age")%>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #ffffff; height: 20px; font-family: Arial">
<td align="left" style="font-size: 15;">
<asp:LinkButton ID="lnkNCode" ForeColor="#336699" runat="server" Text='<%# Eval("Name") %>'
CommandArgument='<%# Eval("Name") %>' CommandName="NCode"></asp:LinkButton>
</td>
<td align="center" style="font-size: 15; text-align: right;">
<%# Eval("Age")%>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
<tr>
<td align="right" height="40px">
<asp:Label ID="lblTotal" runat="server" Font-Bold="true" ForeColor="#336699"></asp:Label>
</td>
</tr>
</FooterTemplate>
</asp:Repeater>
I know this is not correct but it is what I have done so far. Is what I am trying to do possible or not?
Thanks.
You are actually pretty close with what you have now. The trick is when you close off your table rows. Try something more like this:
<asp:Repeater ID="RptNCode" runat="server"
OnItemCommand="RptNcode_ItemCommand"
OnItemDataBound="RptNCode_ItemDataBound">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
Name
</td>
<td>
Age
</td>
<td>
Name
</td>
<td>
Age
</td>
</tr>
<tr>
<td>
<%# Eval("Name") %>
</td>
<td>
<%# Eval("Age") %>
</td>
</ItemTemplate>
<AlternatingItemTemplate>
<td>
<%# Eval("Name") %>
</td>
<td>
<%# Eval("Age") %>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Notice how the AlternatingItemTemplate
keeps the same table row going for another two columns, placing the next record in your datatable on the same row. Then when it reaches the ItemTemplate
again, it adds another row of header information and starts all over again.