kaisersoze Posted February 4, 2004 Posted February 4, 2004 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? Quote Note: I think as a programmer not as a human, so use my answer at your will
kahlua001 Posted February 4, 2004 Posted February 4, 2004 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. Quote
Ice725 Posted March 22, 2005 Posted March 22, 2005 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. 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.