473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

dynamically changing row color in a datagrid

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

Apr 2 '06 #1
2 3974
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

Apr 2 '06 #2
Thanks...

How would the WebControl look?

Sonny
"Phillip Williams" <WE******@newsgroups.nospam> wrote in message
news:33**********************************@microsof t.com...
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

Apr 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
How do I change the datagrid column width dynamically when the grid's being loaded? VM
6
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a...
2
by: gh0st54 | last post by:
hi still working on changing my data grid headers using resource files the thing is i always gat a count of 0 for my datagrid columns count, when will i get the columns count and when should i...
4
by: bill | last post by:
Can I add multiple datagrid controls dynamically at runtime? I want to break up my dataset into separate datagrids, so I can insert a "<p style="page-break-before: always"> tag between them. ...
4
by: dyw55a | last post by:
Donna Mar 15, 10:11 am show options Newsgroups: microsoft.public.dotnet.framework.adonet From: "Donna" <dyw...@yahoo.com> - Find messages by this author Date: 15 Mar 2005 10:11:56 -0800...
3
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns,...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
1
by: Veeves | last post by:
I would like to change the width of a datagrid column at run time. I have noticed when creating a datagrid, if the header text is shorter than the data in the column, then the column width set by...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.