Sharepoint Insight by Namwar Rizvi

Sharepoint Tips, Tricks and inside knowledge from real world experience by Namwar Rizvi

How to use Case statement in RenderPattern of a Custom Field Type

Posted by namwar on October 14, 2009


While designing a custom field type, you may sometime need to render different HTML based on the value of field. For example, if you want to display Red,Amber, Green traffic light images to highlight High,Medium, Low value then you need to dynamically switch image url based  on the value of the field.

In CAML, you have Case structure to implement this switching logic. It works very much like the C# switch-case statement. Following is an example of RenderPattern of a custom field which display different images based on the value of the field.

<RenderPattern Name="DisplayPattern">
      <Switch>
        <Expr>
          <Column />
        </Expr>
        <Case Value="1" >
          <HTML><![CDATA[<img alt="Red" src="/_layouts/IMAGES/ewr210m.gif" />]]></HTML>
         </Case>
        <Case Value="2" >
          <HTML><![CDATA[<img alt="Amber" src="/_layouts/IMAGES/ewr211m.gif"]]></HTML>
        </Case>
        <Case Value="3" >
          <HTML><![CDATA[<img alt="Green" src="/_layouts/IMAGES/ewr209m.gif"]]></HTML>
        </Case>
        <Default>
            <HTML><![CDATA[<span>No Value</span>]]></HTML>
        </Default>
      </Switch>
    </RenderPattern>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: