rudi Posted October 4, 2007 Report Share Posted October 4, 2007 Hi, What I'm looking for is a way to visualize to a user that 2 records belong together. In the example below Product GroupID harddisk 1 usbstick 1 monitor 2 monitor cable 2 microphone 3 speakers 3 speaker cable 3 I would like the first 2 records (belong together cause of the groupid) to have a white background, the second two records to have a light blue background, the next three white again etc. Is this something I would try to do in the onBound event? Has somebody done this before? Thanks, Rudi. Quote Link to comment Share on other sites More sharing options...
AngelR Posted October 4, 2007 Report Share Posted October 4, 2007 Rudi, You are looking for a Conditional Formatting. Below you'll find a way to do it. It works best if you sort the grid by GroupID Field first, and the code should be in the DataBound Event. protected void Grid1_DataBound(object sender, EventArgs e) { int OldGroupID = Convert.ToInt32(Grid1.Items[0].DataValues["GroupID"]); System.Drawing.Color Blue = System.Drawing.Color.Blue; System.Drawing.Color Green = System.Drawing.Color.Green; System.Drawing.Color Color1 = Blue; foreach (GridItem currItem in Grid1.Items) { int CurrentGroupID = Convert.ToInt32(currItem.DataValues["GroupID"]); if (CurrentGroupID == OldGroupID) currItem.Style.BackColor = Color1; else if (Color1 == Blue) { Color1 = Green; } else { Color1 = Blue; } currItem.Style.BackColor = Color1; OldGroupID = CurrentGroupID; } } You can change not only the BackColor but the font color also. Is that what you need? Quote Link to comment Share on other sites More sharing options...
rudi Posted October 5, 2007 Author Report Share Posted October 5, 2007 This was exactly what I needed! Thanks a lot for your quick support. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.