Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 545.7k

Totals not getting displayed

Oct 17 2022 5:11 AM

Hi

  I have below code but totals not getting displayed in Footer

<table class='table table-bordered datatable-fixed-left datatable-button-html5-basic' id='tbldata'>
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Student Name</th>
                                    <th>Delivered</th>
                                    <th>Returned</th>
                                    <th>Balance</th>
                                </tr>
                            </thead>
                            <tbody>
                                <asp:Repeater ID="rptData" runat="server" OnItemDataBound="rptData_ItemDataBound">
                                    <ItemTemplate>
                                        <tr>
                                            <td>
                                                <asp:Literal ID="ltrlNum" Text="<%# Convert.ToString(Container.ItemIndex + 1) %>" runat="server"></asp:Literal>
                                            </td>
                                            
                                            <td>
                                                <asp:Label ID="lblStudentName" runat="server" Text='<%# Eval("Name") %>'>  </asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblDelivered" runat="server" Text='<%# Eval("Delivered") %>'>   </asp:Label></td>                                          
                                            <td>
                                                <asp:Label ID="lblReturned" runat="server" Text='<%# Eval("Returned") %>'> </asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblBalance" runat="server" Text=''></asp:Label></td>
                                        </tr>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <tr>
                                            <td></td>
                                            <td>Total</td>
                                            <td><asp:Label ID="lblDeliveredTotal" runat="server" /></td>
                                            <td><asp:Label ID="lblReturnedTotal" runat="server" /></td>
                                            <td><asp:Label ID="lblBalanceTotal" runat="server" /></td>
                                        </tr>
                                        </table>
                                    </FooterTemplate>
                                </asp:Repeater>
                            </tbody>
                        </table>


protected void rptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    RepeaterItem rptitem = e.Item;

                    int sumOfTwocolumn = Convert.ToInt32(((Label)e.Item.FindControl("lblDelivered")).Text) -
                    Convert.ToInt32(((Label)e.Item.FindControl("lblReturned")).Text);

                    totDelivered += Convert.ToInt32(((Label)e.Item.FindControl("lblDelivered")).Text);
                    totReturned += Convert.ToInt32(((Label)e.Item.FindControl("lblReturned")).Text);

                    ((Label)e.Item.FindControl("lblBalance")).Text = Convert.ToString(sumOfTwocolumn);

                    if (e.Item.ItemType == ListItemType.Footer)
                    {
                        ((Label)e.Item.FindControl("lblDeliveredTotal")).Text = "Total : ";
                        ((Label)e.Item.FindControl("lblReturnedTotal")).Text = totDelivered.ToString();
                        ((Label)e.Item.FindControl("lblBalanceTotal")).Text = totReturned.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
                ShowMessage("Oops...", ex.Message, "error");
            }
        }

Thanks


Answers (1)