datagrid calculation question

kaisersoze

Centurion
Joined
Aug 27, 2003
Messages
152
I have a datagrid, the data grid clontains these columns and data is fed by datareader from database. Columns: from time, and to time, diffTime, Quantiy, Price, total. difftime and total are calculation fields. difftime = fromtime - totime and total = quantity * Price.
how to do?
 
do you calculations in the Itemdatabound sub. if the calculation is for each row, then do e.item.cells(index).text = value or if its for each column, then set a page variable that you calculate in this sub, then check for the itemtype = footer, then write to the appropriate cells.
 
I have set up the ItemDataBound, but for some reason, it addings the columns twice!

I set up a breakpoint and watched the e.Item.ItemType.

Code:
public void DataGrid_ItemDataBound(.....)
{

string thetype = e.Item.ItemType.ToString();

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
    Calc(e.Item.Cells[1].Text);
}
else if (e.Item.ItemType == ListItemType.Footer)
{
    e.Item.Cells[0] = "Total";
    e.Item.Cells[1] = myTotal.ToString();
}
}

I set up my DataGrid to query only 1 row from the DB. So my DataGrid has a Header row, the data row, and a footer row. I watch it loop through and I see the values of typetype as Header, Header, Item, Item, Footer, Footer... If I'm not mistaken, it should only loop through 3 times, for header, item, footer?

Any ideas? I did DataGrid1.DataBind() only once, and I filled the dataset with the DataAdapter.
 
Back
Top