Jump to content
Software FX Community

records with the same groupid highlighted together


rudi
 Share

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...