dynamically changing row color in a datagrid

S

Sonny Sablan

I would like to dynamically change the row color in a datagrid...

I have a list (from a db) where users can mark certain records. When they
are marked I want to display the row in the specified color of the user. i.e
Joe = BLUE, Ed = YELLOW, etc. All other rows can be set to NO COLOR.

I cannot seem to find a way to do this with the web control. Can you help?

Sonny
 
G

Guest

If you have the color preference of each user saved on a field in your
datatable that you bound to the datagrid then you can handle the
ItemDataBound event to change the color or each row like this:

protected void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

e.Item.Style.Add("background-color",((DataRowView)e.Item.DataItem)["UserPreferredColor"]);
}
}
 
S

Sonny Sablan

Thanks...

How would the WebControl look?

Sonny


Phillip Williams said:
If you have the color preference of each user saved on a field in your
datatable that you bound to the datagrid then you can handle the
ItemDataBound event to change the color or each row like this:

protected void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

e.Item.Style.Add("background-color",((DataRowView)e.Item.DataItem)["UserPreferredColor"]);
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Sonny Sablan said:
I would like to dynamically change the row color in a datagrid...

I have a list (from a db) where users can mark certain records. When they
are marked I want to display the row in the specified color of the user.
i.e
Joe = BLUE, Ed = YELLOW, etc. All other rows can be set to NO COLOR.

I cannot seem to find a way to do this with the web control. Can you
help?

Sonny
 

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

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top