Pravallika
Pravallika

Reputation: 57

How to fetch the Item Property/Fields in Sitecore?

I am trying to fetch a field called footer from the Item FooterComponent and want to display.This is the code I have tried but cannot fetch and display.

cs code:

Item footerText=Sitecore.content.Database.GetItem(GUID);
string MyFooter=FooterText["Footer"];
txtFooter.Item = MyFooter;

ascx code:

<sc:fieldrenderer runat="server" id="txtFooter" fieldname="Footer"/>

Upvotes: 1

Views: 1153

Answers (1)

Marek Musielak
Marek Musielak

Reputation: 27132

You should not set a string value of the field to the field renderer. Just set correct item and field name:

Item footerTextItem = Sitecore.content.Database.GetItem(GUID);
txtFooter.Item = footerTextItem;
<sc:fieldrenderer runat="server" id="txtFooter" fieldname="Footer"/>

See more information here: https://sitecoresandbox.com/tag/fieldrenderer/

Also read What's a good way to set the Item or DataSource attribute of a FieldRenderer?

Upvotes: 3

Related Questions