gofor.net
gofor.net

Reputation: 4298

Repeater control with nested elements TR TD

I want to show my data in the format like below:

<table>
  <tr>
     <td></td>
     <td></td>
     <td></td>
     ...
  </tr>
  <tr>
     <td></td>
     <td></td>
     <td></td>
     ...
  </tr>
   .
   .
   .
</table>

I am bit confused about how to represent the data. I am thinking to use the repeater control for this structure. But will it need a nested repeater control or it can be done using the single repeater control? Can anybody please suggest me the proper way?

Thanks in advance.

Update :: In my case and are not in static order they are fully dynamic.In some cases may have the single but in some case they me be 10-20 in count.I need to show the score for test in those structure.for example:

<table>
  <tr>
    <td>10</td>
    <td>5</td>
    <td>30</td>
  </tr>
  <tr>
    <td>40</td>
    <td>34</td>
  </tr>
   .
   .
   .
<table>

like wise.In simple word when the score record for one user is completed I need to add new record in the new fresh .

Upvotes: 1

Views: 1729

Answers (4)

gofor.net
gofor.net

Reputation: 4298

I finally done this with the dynamic table in asp.net.Like RDSAGAR did,but by code behind.Thanks for all your support.

Upvotes: 0

Mikey Mouse
Mikey Mouse

Reputation: 3088

You could make a Repeater like this

<asp:Repeater ID="rptMyRepeater" runat="server" >
     <HeaderTemplate>
          <table>
            <th>
               <td>
                  Header 1
               </td>
               <td>
                  Header 2
               </td>
             </th>
      </HeaderTemplate>
      <ItemTemplate>
          <tr>
             <td>
                 <asp:HiddenField runat="server" ID="hfHolderId" Value='<%# DataBinder.Eval(Container.DataItem, "HolderId") %>' />
                 <asp:TextBox runat="server" ID="tbText1" Text='<%# DataBinder.Eval(Container.DataItem, "Text1") %>' />
             </td>
             <td>
                 <asp:TextBox runat="server" ID="tbText2" Text='<%# DataBinder.Eval(Container.DataItem, "Text2") %>' />
             </td>
           </tr>
       </ItemTemplate>
       <FooterTemplate>
           </table>
       </FooterTemplate>
</asp:Repeater>

Then have a class to hold your data

    public class MyHolder()
    {
         public string HolderId {get;set;}
         public string Text1 {get;set;}
         public string Text2 {get;set;}
    }

Then make a list of these and bind them to your Repeater

    List<MyHolder> myHolderList = new List<MyHolder>();
    myHolderList.Add(new MyHolder {1, "hi", "hello"});
    //Add a few of these

    rptrptMyRepeater.DataSource = myHolderList;
    rptMyRepeater.DataBind();

All this was just outta my head so there my be syntax errors in there

Upvotes: 0

RDSAGAR
RDSAGAR

Reputation: 96

One solution from Old Classic way is nested loop

<table>
<% for(int loop1 = 0; loop1 <= condition1 ; loop1++){
       System.Console.WriteLine("<tr>");
       for(int loop2 = 0; loop2 <= condition2 ; loop2++){
           System.Console.WriteLine("<td>");
           System.Console.WriteLine("Your Data");
           System.Console.WriteLine("</td>");
       }
       System.Console.WriteLine("</tr>");
   } %>
</table>

Upvotes: 1

Johnny_D
Johnny_D

Reputation: 4652

Why are you using repeater? It's rather obsolete component. Use ListView instead. It's much more flexible in configuration and manipulation.

Please use solution suggested here by Merrimack

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

Upvotes: 4

Related Questions