Is it possible to make a Repeater line not repeat ? c#

Asked

Viewed 245 times

0

Is it possible to make a Repeater line not repeat ? Or to bind a few lines of the FooterTemplate of Repeater ? I need the last line I tried to put on Footertemplate not to repeat, because it’s the total values. When I leave on ItemTemplate it displays 3 times according to the number of lines that the datatable possesses.

It was supposed to look like this: Era pra ficar assim

But when I put it on Footertemplate it’s like this: inserir a descrição da imagem aqui

My code:

//ASPX

<FooterTemplate>
    <tr>
        <td colspan="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>
  • You can’t leave the last line out of the loop?

  • @So, I’ve already left only that does not fill this last line according to what you need with what I played to give Bind

  • Is there any way you can show how it is appearing and how it should appear? Like images, even with fictitious data?

  • Ready @Willian, would have to look like the first image.

  • The total values are calculated at what point? You came to check whether the calls of "Totalpurchase Value" and etc are returning the values?

  • @Willian, yes, are returning values, they are loaded at the moment I call the method that returns pro datasource from Peater.

Show 1 more comment

1 answer

2


I don’t know and I’ve never used Eval within the FooterTemplate. You can create a method in your code to calculate the sum of the columns of DataTable and call on the Repeater

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

Thus:

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

Full ASPX 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));
        }

    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.