Is it possible to have a repeater line not repeat? W#

0

Is it possible to have a repeater line not repeat? Or bind in lines of FooterTemplate of Repeater ? I need the last line I tried to put in FooterTemplate does not repeat, because they are the total values. When I leave in ItemTemplate it displays 3 times according to the number of lines that datatable has.

It was supposed to look like this:

ButwhenIputitinFooterTemplateitlookslikethis:

Mycode:

//ASPX

<FooterTemplate><tr><tdcolspan="2" class="tbFundoColVazia">
            <b>
                <asp:Label ID="Label46" class="fontlbl" runat="server" Text="Totais"></asp:Label></b>
        </td>
        <td id="colCompraQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalCompra") %>
        </td>
        <td id="colCompraValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalCompra")).Replace("R$", "") %>
        </td>
        <td id="colDevolucaoQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalDevolucao") %>
        </td>
        <td id="colDevolucaoValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalDevolucao")).Replace("R$", "") %>
        </td>
        <td id="colRetornoQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalRetorno") %>
        </td>
        <td id="colRetornoQValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalRetorno")).Replace("R$", "") %>
        </td>
        <td id="colVendaQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalVenda") %>
        </td>
        <td id="colVendaValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalVenda")).Replace("R$", "") %>
        </td>
        <td id="colDoacaoQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalDoacao") %>
        </td>
        <td id="colDoacaoValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalDoacao")).Replace("R$", "") %>
        </td>
        <td id="colReenvioQtdeTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# Eval("qtdTotalReenvio") %>
        </td>
        <td id="colReenvioValorTotais" style="font-weight: bold" class="tbFundoColVazia">
            <%# string.Format("{0:C}", Eval("valorTotalReenvio")).Replace("R$", "") %>
        </td>
    </tr>
</FooterTemplate>
    
asked by anonymous 16.11.2016 / 18:15

1 answer

2

I do not know and have never used Eval within FooterTemplate . You can create a method in your code to calculate the sum of the columns of DataTable and call in Repeater

  protected decimal Total(string campo)
  {
            return Convert.ToDecimal(dt.Compute($"Sum({campo})", string.Empty));
  }

So:

<FooterTemplate>
                <tfoot>
                    <tr>
                        <td><%# Total("colCompraQtde") %></td>
                        <td><%# Total("colCompraValor") %></td>
                        <td><%# Total("colDevolucaoQtde") %></td>
                    </tr>
                </tfoot>
</FooterTemplate>

ASPX complete example:

<asp:Repeater ID="rptVendas" runat="server">
            <HeaderTemplate>
                <table>
                    <thead>
                      <th></th>
                      <th></th>
                      <th></th>
                    </thead>
                    <tbody>
            </HeaderTemplate>
            <ItemTemplate>
              <tr class="cor1">
                  <td><%# Eval("colCompraQtde") %></td>
                  <td><%# Eval("colCompraValor") %></td>
                  <td><%# Eval("colDevolucaoQtde") %></td>
              </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr class="cor2">
                    <td><%# Eval("colCompraQtde") %></td>
                    <td><%# Eval("colCompraValor") %></td>
                    <td><%# Eval("colDevolucaoQtde") %></td>
               </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
                 </tbody>
                <tfoot>
                    <tr>
                        <td><%# Total("colCompraQtde") %></td>
                        <td><%# Total("colCompraValor") %></td>
                        <td><%# Total("colDevolucaoQtde") %></td>
                    </tr>
                </tfoot>
               </table>
            </FooterTemplate>
        </asp:Repeater>

C #

public partial class WebForm1 : System.Web.UI.Page
    {
        private DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            dt = new DataTable();
            dt.Columns.Add("colCompraQtde", typeof(decimal));
            dt.Columns.Add("colCompraValor", typeof(decimal));
            dt.Columns.Add("colDevolucaoQtde", typeof(decimal));

            dt.Rows.Add(1, 5, 0);
            dt.Rows.Add(1, 2.5, 0);
            dt.Rows.Add(1, 3, 0);

            rptVendas.DataSource = dt;
            rptVendas.DataBind();
        }

        protected decimal Total(string campo)
        {
            return Convert.ToDecimal(dt.Compute($"Sum({campo})", string.Empty));
        }

    }
    
16.11.2016 / 20:21