Jump to content
Software FX Community

records with the same groupid highlighted together


rudi

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...