How to change repeater line color at run time

1

How do I change the line color of Repeater running? Repeater lines are loaded through what comes from the database.

Example: If there are 3 lines, when displaying on repeater, the first line is one color, the second line is another, and the third line is another.

My code:

// ASPX

<asp:Repeater ID="repeater1" runat="server">
 <HeaderTemplate>
  <tr>
  <!-- Coluna Compra -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>
  <!-- Coluna Devolução -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>
  <!-- Coluna Retorno -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>
  <!-- Coluna Venda -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>     
  <!-- Coluna Doação -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>
  <!-- Coluna Reenvio -->
   <td class="aFaturarTopo"><i>Qtde.</i></td>
   <td class="aFaturarTopo"><i>Valor</i></td>
  </tr>
</HeaderTemplate>
    <ItemTemplate>
      <tr>
      <td colspan="2" class="tbFundoH">
      <asp:Label ID="Label4" class="fontlbl" runat="server" Text='<%# Eval("Categorias") %>'></asp:Label>
      </td>
    <!-- Coluna Compra -->
    <td id="colCompraQtdeCat" class="tbFundoH">
    <asp:Label ID="Label8" class="fontlbl" runat="server" Text='<%# Eval("qtdCompraCat") %>'></asp:Label>
    </td>
    <td id="colCompraValorCat" class="tbFundoH">
    <asp:Label ID="Label9" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorCompraCat")).Replace("R$", "") %>'></asp:Label>
    </td>
  <!-- Coluna Devolução -->
    <td id="colDevolucaoQtdeCat" class="tbFundoH">
    <asp:Label ID="Label35" class="fontlbl" runat="server" Text='<%# Eval("qtdDevolucaoCat") %>'></asp:Label>
    </td>
    <td id="colDevolucaoValorCat" class="tbFundoH">
    <asp:Label ID="Label47" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorDevolucaoCat")).Replace("R$", "") %>'></asp:Label>
    </td>
  <!-- Coluna Retorno -->
    <td id="colRetornoQtdeCat" class="tbFundoH">
    <asp:Label ID="Label48" class="fontlbl" runat="server" Text='<%# Eval("qtdRetornoCat") %>'></asp:Label>
    </td>
    <td id="colRetornoValorCat" class="tbFundoH">
    <asp:Label ID="Label49" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorRetornoCat")).Replace("R$", "") %>'></asp:Label>
    </td>
 <!-- Coluna Venda -->
   <td id="colVendaQtdeCat" class="tbFundoH">
   <asp:Label ID="Label50" class="fontlbl" runat="server" Text='<%# Eval("qtdVendaCat") %>'></asp:Label>
    </td>
   <td id="colVendaValorCat" class="tbFundoH">
                                                        <asp:Label ID="Label51" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorVendaCat")).Replace("R$", "") %>'></asp:Label>
   </td>
 <!-- Coluna Doação -->
   <td id="colDoacaoQtdeCat" class="tbFundoH">
   <asp:Label ID="Label52" class="fontlbl" runat="server" Text='<%# Eval("qtdDoacaoCat") %>'></asp:Label>
   </td>
   <td id="colDoacaoValorCat" class="tbFundoH">
   <asp:Label ID="Label53" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorDoacaoCat")).Replace("R$", "") %>'></asp:Label>
   </td>
  <!-- Coluna Reenvio -->
    <td id="colReenvioQtdeCat" class="tbFundoH">
    <asp:Label ID="Label54" class="fontlbl" runat="server" Text='<%# Eval("qtdReenvioCat") %>'></asp:Label>
        </td>
      <td id="colReenvioValorCat" class="tbFundoH">
     <asp:Label ID="Label55" class="fontlbl" runat="server" Text='<%# string.Format("{0:C}", Eval("valorReenvioCat")).Replace("R$", "") %>'></asp:Label>
     </td>
     </tr>                             
       </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
     </asp:Repeater>
    
asked by anonymous 16.11.2016 / 13:24

1 answer

3

Judging from <tr> and <td> on Repeater , you'll have a table outside Repeater . Do for CSS, putting the class in the table:

HTML:

<table class="table-striped">
    <asp:repetear..
    ...
</table>

CSS:

.table-striped tr:nth-child(odd) td {
  background-color: #cor-1;
}
.table-striped tr:nth-child(even) td {
  background-color: #cor-2;
}
    
16.11.2016 / 13:32