Datagrid footer not displaying data

N

.Net Sports

the below itemdatabound function works , displays all the grand totals
in the footer control of the datagrid:

private void dglvboard_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataRowView rowData;
decimal price;
decimal priceWk;
decimal newssum;
decimal newssumWk;
System.Web.UI.WebControls.Literal Amount_RevenueLabel = null;
System.Web.UI.WebControls.Literal Amount_RevenueLabelWk = null;
System.Web.UI.WebControls.Literal NewsLabel = null;
System.Web.UI.WebControls.Literal NewsLabelWk = null;
/System.Web.UI.WebControls.Literal totalLabel = null;
System.Web.UI.WebControls.Literal totalLabelWk = null;
System.Web.UI.WebControls.Literal newstotalLabel = null;
System.Web.UI.WebControls.Literal newstotalLabelWk = null;
// check the type of item that was databound and only take action if
it
// was a row in the datagrid
switch (e.Item.ItemType)
{
case ListItemType.AlternatingItem:
case ListItemType.EditItem:
case ListItemType.Item:
case ListItemType.SelectedItem:
// get the data for the item being bound
rowData = (DataRowView)(e.Item.DataItem);

// get the value for the list price and add it to the sum
// get the control used to display the list price
// NOTE: This can be done by using the FindControl method of the
// passed item because ItemTemplates were used and the anchor
// controls in the templates where given IDs. If a standard
// BoundColumn was used, the data would have to be accessed
// using the cellscollection (e.g.
e.Item.Cells(1).controls(1)
// would access the label control in this example.

// now format the list price in
currency format

// get the value for the discounted price and add it to the sum



price = System.Convert.ToDecimal(rowData["dbltempTotalVolume"]);
priceWk = System.Convert.ToDecimal(rowData["dblTotalVolumeWk"]);

newssum = DBValueToInt(rowData["news"], 0);
////-//converting news like price et priceWk above
newssum = System.Convert.ToDecimal(rowData["news"]);
newssumWk = System.Convert.ToDecimal(rowData["newsWk"]);



mAmount_RevenueTotal += price/2;
mAmount_RevenueTotalWk += priceWk/2;
mNewsTotal += newssum/2;
mNewsTotalWk += newssumWk/2;
////-///temp test cg from init dblTotalVolume



// get the control used to display the discounted price
Amount_RevenueLabel = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblAmount_Revenue"));
Amount_RevenueLabelWk = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblAmount_RevenueWk"));
NewsLabel = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblNews"));
NewsLabelWk = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblNewsWk"));


// now format the discounted price in currency format
Amount_RevenueLabel.Text = price.ToString("C2");
Amount_RevenueLabelWk.Text = priceWk.ToString("C2");
NewsLabel.Text = newssum.ToString();
NewsLabelWk.Text = newssumWk.ToString();
break;
case ListItemType.Footer:
// get the control used to display the total of the list prices

// prices and set its value to the total of the discounted prices
totalLabel = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblAmount_RevenueTotal"));
totalLabel.Text = mAmount_RevenueTotal.ToString("C2");
totalLabelWk = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblAmount_RevenueTotalWk"));
totalLabelWk.Text = mAmount_RevenueTotalWk.ToString("C2");
newstotalLabel = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblNewsTotal"));
newstotalLabel.Text = mNewsTotal.ToString();

newstotalLabelWk = (System.Web.UI.WebControls.Literal)
(e.Item.FindControl("lblNewsTotalWk"));
newstotalLabelWk.Text = mNewsTotalWk.ToString();
break;
default:
// ListItemType.Header, ListItemType.Pager, or
ListItemType.Separator
// no action required
break;
}

..but the following does not display the grand total in the footer
rows, tho it does display all the other rows
in the datagrid:
//
private void dglvboard_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch (e.Item.ItemType)
{
case ListItemType.AlternatingItem:
//e.Item.BackColor = Color.Aqua;
break;
case ListItemType.Footer:
e.Item.Cells[1].Text = mAmount_RevenueTotal.ToString("C2");
e.Item.Cells[1].HorizontalAlign = HorizontalAlign.Right;
e.Item.Cells[2].Text = mAmount_RevenueTotalWk.ToString("C2");
e.Item.Cells[2].HorizontalAlign = HorizontalAlign.Right;
e.Item.Cells[3].Text = mNewsTotal.ToString();
e.Item.Cells[3].HorizontalAlign = HorizontalAlign.Right;
e.Item.Cells[4].Text = mNewsTotalWk.ToString();
e.Item.Cells[4].HorizontalAlign = HorizontalAlign.Right;
break;
}
}

The footer template in these two examples is exactly the same (I'll
show you the one for the amount_revenue total display):
<FooterTemplate>
<asp:Literal id="lblAmount_RevenueTotal" runat="server" />
</FooterTemplate>

..in both cases, the function is drawing data from a datarow that is
configured the same way. But am wondering what i am missing in the
second function example I have listed. I can provide further code
samples as far as how vars are being initialized and called.
??
TIA
.netsports
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I think that your code is not very efficient, updating the total label on
each databound is not very good idea, it's much better to store the running
value in a protected variable and just bind that value in the footer.

You do nt update the total in the second example. unless you miss some code.

Do the above suggestion and all will be easier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top