Link to home
Start Free TrialLog in
Avatar of gfk76
gfk76

asked on

Sumtotal in Datalist

Hi Experts!

I was hoping you could help with an issue, I have been struggling with.

I have a datalist with several invoice sums.
I would like Sum Total in the Footer of the Datalist.
Unfortunately, I'm not able to make it work. I do not get any errormessage, but the Sum total does not show.
Could someone be kind enough to take a look at this code.

Sub bind()
        Dim dt As DataTable
        Dim dr As DataRow
        Dim SumInvoiced As Integer

        dt = New DataTable()
        dt.Columns.Add(New DataColumn("ContryCode", GetType(String)))
        dt.Columns.Add(New DataColumn("CompanyName", GetType(String)))
        dt.Columns.Add(New DataColumn("TotalInvoiced", GetType(String)))
        dt.Columns.Add(New DataColumn("TotInvoiced", GetType(String)))

        Dim mySqlConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
        Dim MySqlCmd As SqlCommand = New SqlCommand("Select ContryCode, CompanyName from Tab_Campaigns WHERE ContryCode=" + Request.QueryString("KlientNr"), mySqlConn)
        MySqlCmd.CommandType = CommandType.Text
        mySqlConn.Open()
        Dim Reader7 As SqlDataReader = MySqlCmd.ExecuteReader()
        While Reader7.Read()
            dr = dt.NewRow()
            dr(0) = getKlientNr(Reader7("ContryCode"))
            dr(1) = Reader7("CompanyName")
            dr(2) = TotalInvoiced(Reader7("CampaignCode"))
           
            SumInvoiced += TotalInvoiced(Reader7("CampaignCode"))
            dr(3) = TotInvoiced
           
           dt.Rows.Add(dr)
        End While

        Reader7.Close()
        mySqlConn.Close()
        dbList.DataSource = New DataView(dt)
        dbList.DataBind()
end sub

###Datalist

<asp:datalist id="dbList" runat="server" Width="985px" ShowFooter="true" RepeatLayout="Flow" RepeatDirection="Horizontal" RepeatColumns="2" BorderColor="Black" BorderStyle="None" CellSpacing="1" BackColor="White" CellPadding="3" BorderWidth="1px" GridLines="Both">
         <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
      <HeaderTemplate>
            <TABLE id="AutoNumber5" style="BORDER-COLLAPSE: collapse" borderColor="#111111" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                                       <td width="10%">Contry</td>
                  <td width="10%">Company Name</td>
                  <td width="10%">Total invoiced</td>
              </TR>
            </TABLE>
      </HeaderTemplate>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
      <ItemStyle HorizontalAlign="Justify" ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
            <ItemTemplate>
                  <TABLE id="AutoNumber6" style="BORDER-COLLAPSE: collapse" borderColor="#111111" cellSpacing="0" cellPadding="0" width="100%" border="0">
                               <TR align="center">
                  <TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container.DataItem, "ContryCode") %>&nbsp;</FONT></SPAN></TD>
                  <TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container.DataItem, "CompanyName") %>&nbsp;</FONT></SPAN></TD>
                  <TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container.DataItem, "TotalInvoiced") %>&nbsp;</FONT></SPAN></TD>
                  </TR>
                  <TR>
                  <TD width="50%" colSpan="2">&nbsp;</TD>
                  </TR>
                  </TABLE>
            </ItemTemplate>
            <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Gray"></HeaderStyle>
                <FooterTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TotInvoiced") %>'></asp:Label>
                </FooterTemplate>
</asp:datalist>                        
SOLUTION
Avatar of ethoths
ethoths

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gfk76
gfk76

ASKER

I tried that, but still nothing.
No value what so ever in the label....


ASKER CERTIFIED SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes dbaduck is right. The SumInvoiced need to be a class level variable. Dim it at the class level and everything will be fine.

dbaducks other suggestions will also work but they take a bit more effort since you're already gone this far.
Avatar of gfk76

ASKER

Thanks guys!
I'll be abel to sleep tonight!

Putting SumInvoiced outside the sub was the trick!