Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Note: I think as a programmer not as a human, so use my answer at your will
Posted
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.
  • 1 year later...
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...