data grid conditional row formatting

B

Brian Henry

How would i format a web data grid conditionally?

If column 1 is the value true i want the row to be white, else if it is
false i want the row to be blue, thanks
 
M

Martin Marinov

use ItemDataBound event of datagrid control
and

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
string color = "";
if ( bool.Parse(e.Item.Cells[0].Text) )
color = "#FF0000";
else
color = "#00FFFF";

for ( int i=0; i < e.Item.Cells.Count; i ++ )
{
e.Item.Cells.BackColor = Color.FromName(color);
}
}
}

where in the first column i have the true/false value as a text

Regards
Martin
 
B

Brian Henry

thanks

Martin Marinov said:
use ItemDataBound event of datagrid control
and

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem )
{
string color = "";
if ( bool.Parse(e.Item.Cells[0].Text) )
color = "#FF0000";
else
color = "#00FFFF";

for ( int i=0; i < e.Item.Cells.Count; i ++ )
{
e.Item.Cells.BackColor = Color.FromName(color);
}
}
}

where in the first column i have the true/false value as a text

Regards
Martin


Brian Henry said:
How would i format a web data grid conditionally?

If column 1 is the value true i want the row to be white, else if it is
false i want the row to be blue, thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top