Monday, 30 June 2014

How to bind sitecore field inline in repeater control?

Friends, How are you all doing?
I know you may have a question - "Long time, No Posts?" Yeah, I got some halt (e.g. busy with new project) in my sitecore journey. And in this halt - I have learnt many new things, now it's time to share these leanings.
So let's start knowledge sharing.

Scenario:
Have you come across a requirement where you are using asp.net control (e.g. repeater control) and you want to bind sitecore item field values inline without using any asp.net or sitecore control? If so, then this post may help you.

Many of you have rendered sitecore field value inline using below approach which is completely correct.
 
        
            
         
       
But, what if you want to bind sitecore field value without using any sitecore control (e.g. sc:fieldrender) or asp.net control?
In such case, you can use following approach:

        
            <%# ((Sitecore.Data.Items.Item)(Container.DataItem)).Fields["Text Heading"].Value %>
         
    
This is how you can render sitecore field inline:
<%# ((Sitecore.Data.Items.Item)(Container.DataItem)).Fields["Text Heading"].Value %>

2 comments:

  1. Hello,

    May I know why you have used onitemdatabound="OnLandingPageItemCreated event?

    is it necessary?

    Thanks

    ReplyDelete
  2. Yes, it's necessary otherwise it will not bind the container item.

    ReplyDelete