0

I'm using a repeater for a table in ASP.NET using C#

And I am trying to set the repeater to use a default of 26 rows.

No matter if I have more or less info.

If i have less, I want the rest of the row to be empty, if i have more then 26 rows of info it should go to a second, third, etc. page.

What should i do?

Here is my code

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="sqltoolinv1"  >
   <HeaderTemplate>
      <table style="width: 86.7%; border-collapse: collapse; border: 1px solid black;" align="center">
         <tr align="center" class="text" style="background-color: gray">
            <th style="width: 5.14%;">No.</th>
            <th style="width: 20.22%;">Tool Nomenclature or Description</th>
            <th style="width: 11.4%;">Purchase Date</th>
            <th style="width: 9.56%;">Original Cost</th>
            <th style="width: 9.93%;">Condition of Tool</th>
            <th style="width: 8.456%;">Drawer or Shelf</th>
            <th style="width: 21.32%;">Remarks</th>
         </tr>
   </HeaderTemplate>
   <ItemTemplate>
   <tr align="left">
   <td>
   <asp:Label runat="server" ID="lbnum"
      Text='<%# Eval("ID") %>' /></td>
   <td>
   <asp:Label runat="server" ID="lbtname"
      Text='<%# Eval("Description") %>' /></td>
   <td>
   <asp:Label runat="server" ID="lbpurdate"
      Text='<%# Eval("[Purchase_Date]") %>' /></td>
   <td>
   <asp:Label runat="server" ID="lboricost"
      Text='<%# Eval("Cost") %>' DataFormatString="{0:C}" /></td>
   <td>
   <asp:Label runat="server" ID="lbtoolcond"
      Text='<%# Eval("Condition") %>' /></td>
   <td>
   <asp:Label runat="server" ID="lbshelf"
      Text='<%# Eval("Location") %>' /></td>
   <td>
   <asp:Label runat="server" ID="lbremarks"
      Text='<%# Eval("Remarks") %>' /></td>
   </tr>
   </ItemTemplate>
   <FooterTemplate>
   </table>
   </FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sqltoolinv1" runat="server"
   ConnectionString="<%$ connectionstrings:webserverconnectionstring %>"
   SelectCommand="SELECT [ID],[Description],[Purchase Date] AS [Purchase_Date],[Cost],[Condition],[Location],[Remarks] FROM [EmpPortalToolInv] WHERE [Payroll] = @Payroll ORDER BY [ID]">
   <SelectParameters>
      <asp:SessionParameter Name="Payroll" SessionField="Payroll" DbType="String" />
   </SelectParameters>
</asp:SqlDataSource>
Jad Chahine
  • 6,849
  • 8
  • 37
  • 59
  • 2
    As far as your question regarding the minimum of 26 rows, I am not sure what to do. But regarding pagination, this is not something that comes out of the box for a `Repeater`. You may want to look a the `DataGrid` or `GridView` controls. They will create tables for you with more elegant solutions for pagination. – Olivier De Meulder Nov 13 '15 at 13:35

1 Answers1

0

I'm not sure that's possible. But you can limit data in list what you send.

var firstPageItems = myList.Take(26);
var secondPageItems = myList.Skip(26).Take(26);

Repeater1.DataSource = firstPageItems;
Repeater1.DataBind();

How to get first N elements of a list in C#

OR

you can pages item by js

for example :

https://www.datatables.net/

Community
  • 1
  • 1
Pavel Kučera
  • 119
  • 10