G
Guest
Hi.
I am trying to calculate the total of a column in a datagrid. The amounts
display fine on the grid, but the value of each cell is "" when
DataGrid1_ItemDataBound is called. A funny thing is that a date column after
the amount column has a valid value for each cell of the date column. Please
help.
Here is my code:
private void DoTotal(string sAmount)
{
try
{
m_dTotal += Double.Parse(sAmount);
}
catch
{
}
}
public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
//e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}
I am trying to calculate the total of a column in a datagrid. The amounts
display fine on the grid, but the value of each cell is "" when
DataGrid1_ItemDataBound is called. A funny thing is that a date column after
the amount column has a valid value for each cell of the date column. Please
help.
Here is my code:
private void DoTotal(string sAmount)
{
try
{
m_dTotal += Double.Parse(sAmount);
}
catch
{
}
}
public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
//e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}