views:

780

answers:

2

I am trying to create a custom view for a sharepoint list, similar to the one explained here:

http://msdn.microsoft.com/en-us/library/ms916812.aspx

I have a column which is a number field with values ranging from 0 to 100.

I need to create a view style which will display an image in the column based on the column value, instead of displaying the value.

If the value is in between 0 to 25, i need to display an image 25.gif If the value is in between 25 to 50, i need to display an image 50.gif ..... and so on.

The calculation involved here is the CEILING function, CEILNG(NumberColumn,25)

The problem is, I need to specify this in CAML, in the VWSTYLES.XML

How can I specify the Ceilnig function in CAML?

A: 

CEILING is used for rounding decimal values. Since you only have a few images, I would just use nested IF functions:

=IF([NumberColumn]>76, "100.gif", IF([NumberColumn]>51, "75.gif",
 IF([NumberColumn]>26,  "50.gif", "25.gif")))

You could also use the MOD function to convert 0-24 to 0, 25-49 to 1, etc. and calculate your image from there.

dahlbyk
Hey thanx for the answer.The link you referred to links to formulas for calculated columns.I have to modify the VWSTYLES.xml file. Does this work in CAML?
ashwnacharya
Could you create a calculated field on your list and then reference that from CAML?
dahlbyk
No i am not supposed to use a calculated field. I need to do that from the VWSTYLES.XML itself
ashwnacharya
I don't believe there's a way to do calculations within the CAML itself. You could use a Switch element with 101 case, but that wouldn't be much fun. Not sure there's a better way though.
dahlbyk
I need it to work with decimal places too... There can't be enough switch cases.. :(
ashwnacharya
A: 

Some other options could be:

As the VWSTYLES.XML is just a really awkward way of rendering html, you could code some javascript into your VWSTYLES.XML to render the image tag with the correct source.

Alternately, develop an ascx control and get the VWSTYLES.XML to render a control instead of HTML. So long as you can register the control on the page correctly.

Nat
hi... Can you please elaborate on how to do it using javascript? More specifically, how do I decide the correct image source? I assume there would be a javascript function which returns the image source based on the column value. But how do I pass the column value to the function?
ashwnacharya
The javascript would depend so much on what your html is like, there is no way I would even be able to start you on the right track. Look at the VWSTYLES.XML and see how Javascript is rendered. If that does not scare you into doing it another way, you may just be okay.
Nat