mhweiss

mhweiss

  • NA
  • 1
  • 0

Help with formatting datagrid element

Nov 14 2005 1:27 PM
I have the following code to format a couple of columns in a Datagrid component. The problem I am having is the text in two of the columns is correctly being set to an empty string but the font.bold property is not being set correctly neither is the currency format being applied. Can anyone show me where I am going wrong here?
Thank you,
Michael

public void dgReport_ItemDataBound(Object sender, DataGridItemEventArgs e)

{

const int WHAT_COL = 0;

const int PTD_COL = 1;

TableCell cell = null;

TableCell cellPtd = null;

string ptd = "0";

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))

{

cell = (TableCell)(e.Item.Controls[WHAT_COL]);

if ((cell.Text == "COMMISSIONS") || (cell.Text == "EXPENSES") || (cell.Text == "TOTAL EXPENSES"))

{

cell.Font.Bold = true;

cellPtd = (TableCell)(e.Item.Controls[PTD_COL]);

cellPtd.Text = "";

}

else if (cell.Text == "NET INCOME")

{

cellPtd = (TableCell)(e.Item.Controls[PTD_COL]);

ptd = cellPtd.Text;

cellPtd.Text = String.Format("{0:c}", Convert.ToDouble(ptd));

}

else

{

cellPtd = (TableCell)(e.Item.Controls[PTD_COL]);

ptd = cellPtd.Text;

cellPtd.Text = String.Format("{0:#,##0.00}", Convert.ToDouble(ptd));

}

}

}