Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dynamically changing row color in a datagrid

Reply
Thread Tools

dynamically changing row color in a datagrid

 
 
Sonny Sablan
Guest
Posts: n/a
 
      04-02-2006
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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      04-02-2006
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" wrote:

> 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
>
>
>
>

 
Reply With Quote
 
 
 
 
Sonny Sablan
Guest
Posts: n/a
 
      04-03-2006
Thanks...

How would the WebControl look?

Sonny


"Phillip Williams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" wrote:
>
>> 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
>>
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
change row color of empty row =?Utf-8?B?aWdvdHlvdXJkb3RuZXQ=?= ASP .Net 3 10-24-2006 12:11 PM
GridView: Row background color= red if row ID = 3 G. Whiz ASP .Net 1 02-24-2006 03:52 PM
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM
DataGrid, changing background color of a Row? =?Utf-8?B?TmVpbA==?= ASP .Net 0 10-07-2004 04:11 PM



Advertisments