locked
Change background color ONLY for two row at a time RRS feed

  • Question

  • Hi,

    this code =Iif(RowNumber(Nothing) Mod , "PaleGreen", "White") will change background color for every other row.  I want to change background color for every two rows.  Any info?

    Tuesday, August 21, 2012 5:42 PM

Answers

  • Hi Rv7a99cv,

    According to your description, you want alternate row color in your tablix, right? If you use a table in your report, you can use RowNumber function to alternate row color. Use the expression below to set the background color:
    =iif((rownumber(nothing)-1) mod 4 >1,"White","Silver")

    If you use a matrix in your report, the RowNumber function in the Matrix is totally different with it in the table because you are always dealing with grouped data in a matrix. In this case, please refer to the steps below to alternate row color.

    1. Add the custom code below to your report:
      dim Counter as integer=0
      Public function getCounter() as Integer
       Counter=Counter+1
       return Counter
      end function
    2. Add a column to the right of the matrix, type the expression below to inserted column:
      =code.getCounter
    3. Change the text-box name to “rownumber” and set the visibility of inserted column to “Hidden”.
    4. Use the expression below to set the background color:
      =iif((reportitems!Textbox32.Value-1) mod 4 > 1,"White","Silver")

    The report looks like below:

    If you have any questions, please feel free to ask.

    Regards,
    Charlie Liao

    Thursday, August 23, 2012 3:18 AM

All replies

  • With a very similar code; just check for less or equal 2:

    =Iif(RowNumber(Nothing) <= 2, "PaleGreen", "White") 


    Olaf Helper
    Blog Xing

    Tuesday, August 21, 2012 5:53 PM
  • HI rv !

    You may get the desired output using below expression;

    =IIF(((RunningValue(Fields!YourColumn.Value.ToString,CountDistinct,Nothing) / 2) Mod 2) < 1,"#f6f6f6", "#ffffff")

    You can specify the above expression on your row and set the Background Color property to above expression.

    Please let me know if this doesn’t work for you. Hope I have answered you correctly.

    Thanks, Hasham Niaz

    Tuesday, August 21, 2012 6:14 PM
    Answerer
  • Thank you for both BUT

    Have a group, child group and details.  If I use =IIF(RunningValue(Fields!groupField.Value,CountDistinct, Nothing) MOD 2 = 1, "blue", "red") then it works very well as long as I have only one group of ChildGroup.  If I get multiple record for childGroup then entire rows based on the Group color will change.  I want to change the code for ChildGroup but does not work

    =IIF(RunningValue(Fields!ChildGroupField.Value,CountDistinct, Nothing) MOD 2 = 1, "blue", "red")

    Note: my detail row always going to have two records only.


    • Edited by rv7a99cv Tuesday, August 21, 2012 9:04 PM
    Tuesday, August 21, 2012 8:54 PM
  • This works only for the first two rows, what about others?

    =Iif(RowNumber(Nothing) <= 2, "PaleGreen", "White") 


    • Edited by rv7a99cv Tuesday, August 21, 2012 9:00 PM
    Tuesday, August 21, 2012 8:55 PM
  • Hi There

    Thanks for your posting. I think you might need to change the scope of your running value expression. So instead of putting nothing please try to put scope as your group name

    =IIF(RunningValue(Fields!ChildGroupField.Value,CountDistinct, "YourGroupName") MOD 2 = 1, "blue", "red")

    =IIF(RunningValue(Fields!ChildGroupField.Value,CountDistinct, "YourGroupName") MOD 2 = 1, "blue", "red") 

    You can put this expression for every group if you would like to change the colour of every group, please change the scope according to your need(Your group name)

    I hope this will help

    If you have any questions please let me know

    Many Thanks

    Syed Qazafi Anjum

    Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.

    Tuesday, August 21, 2012 9:55 PM
  • Hi Syed,

    thanks for yoru reply, here what I get originaly

    what I want is

    I did try the above statement but didn't work.

    Wednesday, August 22, 2012 2:50 PM
  • Hi Rv7a99cv,

    According to your description, you want alternate row color in your tablix, right? If you use a table in your report, you can use RowNumber function to alternate row color. Use the expression below to set the background color:
    =iif((rownumber(nothing)-1) mod 4 >1,"White","Silver")

    If you use a matrix in your report, the RowNumber function in the Matrix is totally different with it in the table because you are always dealing with grouped data in a matrix. In this case, please refer to the steps below to alternate row color.

    1. Add the custom code below to your report:
      dim Counter as integer=0
      Public function getCounter() as Integer
       Counter=Counter+1
       return Counter
      end function
    2. Add a column to the right of the matrix, type the expression below to inserted column:
      =code.getCounter
    3. Change the text-box name to “rownumber” and set the visibility of inserted column to “Hidden”.
    4. Use the expression below to set the background color:
      =iif((reportitems!Textbox32.Value-1) mod 4 > 1,"White","Silver")

    The report looks like below:

    If you have any questions, please feel free to ask.

    Regards,
    Charlie Liao

    Thursday, August 23, 2012 3:18 AM