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.Confi guration.C onfigurati onManager. AppSetting s("Connect ionString" ))
Dim MySqlCmd As SqlCommand = New SqlCommand("Select ContryCode, CompanyName from Tab_Campaigns WHERE ContryCode=" + Request.QueryString("Klien tNr"), mySqlConn)
MySqlCmd.CommandType = CommandType.Text
mySqlConn.Open()
Dim Reader7 As SqlDataReader = MySqlCmd.ExecuteReader()
While Reader7.Read()
dr = dt.NewRow()
dr(0) = getKlientNr(Reader7("Contr yCode"))
dr(1) = Reader7("CompanyName")
dr(2) = TotalInvoiced(Reader7("Cam paignCode" ))
SumInvoiced += TotalInvoiced(Reader7("Cam paignCode" ))
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="Horizonta l" RepeatColumns="2" BorderColor="Black" BorderStyle="None" CellSpacing="1" BackColor="White" CellPadding="3" BorderWidth="1px" GridLines="Both">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></Sele ctedItemSt yle>
<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"></Al ternatingI temStyle>
<ItemStyle HorizontalAlign="Justify" ForeColor="Black" BackColor="#EEEEEE"></Item Style>
<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") %> </FONT></SPAN></TD >
<TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container. DataItem, "CompanyName") %> </FONT></SPAN></TD >
<TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container. DataItem, "TotalInvoiced") %> </FONT></SPAN></TD >
</TR>
<TR>
<TD width="50%" colSpan="2"> </TD>
</TR>
</TABLE>
</ItemTemplate>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Gray"></HeaderS tyle>
<FooterTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container. DataItem, "TotInvoiced") %>'></asp:Label>
</FooterTemplate>
</asp:datalist>
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"
dt.Columns.Add(New DataColumn("TotInvoiced", GetType(String)))
Dim mySqlConn As SqlConnection = New SqlConnection(System.Confi
Dim MySqlCmd As SqlCommand = New SqlCommand("Select ContryCode, CompanyName from Tab_Campaigns WHERE ContryCode=" + Request.QueryString("Klien
MySqlCmd.CommandType = CommandType.Text
mySqlConn.Open()
Dim Reader7 As SqlDataReader = MySqlCmd.ExecuteReader()
While Reader7.Read()
dr = dt.NewRow()
dr(0) = getKlientNr(Reader7("Contr
dr(1) = Reader7("CompanyName")
dr(2) = TotalInvoiced(Reader7("Cam
SumInvoiced += TotalInvoiced(Reader7("Cam
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="Horizonta
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></Sele
<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"></Al
<ItemStyle HorizontalAlign="Justify" ForeColor="Black" BackColor="#EEEEEE"></Item
<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.
<TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container.
<TD width="10%"><SPAN style="FONT-SIZE: 9pt"><FONT face="Arial" color="#666666"><%# DataBinder.Eval(Container.
</TR>
<TR>
<TD width="50%" colSpan="2"> </TD>
</TR>
</TABLE>
</ItemTemplate>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Gray"></HeaderS
<FooterTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.
</FooterTemplate>
</asp:datalist>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
dbaducks other suggestions will also work but they take a bit more effort since you're already gone this far.
ASKER
Thanks guys!
I'll be abel to sleep tonight!
Putting SumInvoiced outside the sub was the trick!
I'll be abel to sleep tonight!
Putting SumInvoiced outside the sub was the trick!
ASKER
No value what so ever in the label....