J
jacqueharper
I need to change the formatting of individual cells in a datagrid. I
cannot figure out how to address individual cells by their column name.
I have a DataTable which contains (for instance) columns called Weight,
Length and Diameter.
The table is bound to a DataGrid, and I am using the ItemDataBound
behavior to execute code that checks values in the table, e.g.:
public void OnDataBindValuesCheck (object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
double testLength =
Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "Length"));
if (testLength > 30)
{
// highlight the cell which contains the value that is
greater then 30.
// e.Item.BackColor will set the background color for the
whole row.
// e.Item.Cells[*int*].BackColor will set the color _if_
I know
// the ordinal number of the cell, but I can't count
on that.
// What I need is something like
e.Item.Cells[*columnNameFromDataTable*].
}
}
}
(see the "comments" in my psuedocode for the dilemna)
Thanks for any help!
Jacque
cannot figure out how to address individual cells by their column name.
I have a DataTable which contains (for instance) columns called Weight,
Length and Diameter.
The table is bound to a DataGrid, and I am using the ItemDataBound
behavior to execute code that checks values in the table, e.g.:
public void OnDataBindValuesCheck (object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
double testLength =
Convert.ToDouble(DataBinder.Eval(e.Item.DataItem, "Length"));
if (testLength > 30)
{
// highlight the cell which contains the value that is
greater then 30.
// e.Item.BackColor will set the background color for the
whole row.
// e.Item.Cells[*int*].BackColor will set the color _if_
I know
// the ordinal number of the cell, but I can't count
on that.
// What I need is something like
e.Item.Cells[*columnNameFromDataTable*].
}
}
}
(see the "comments" in my psuedocode for the dilemna)
Thanks for any help!
Jacque