If using a Droplist field type
Code-behind:
public Item GetLinkedItem(Item item, string itemField)
{
string dropDownItemId = item[itemField];
return Sitecore.Context.Database.GetItem(dropDownItemId);
}
Ascx markup:
<asp:Repeater ID="rptChildren" runat="server">
<ItemTemplate>
<sc:FieldRenderer ID="frTitle" runat="server" FieldName="Title" Item='<%# GetLinkedItem((Sitecore.Data.Items.Item)Container.DataItem, "YourDropLinkFieldName") %>' />
</ItemTemplate
- The value is stored in Sitecore as plain text representing the name* of the selected item. In this case you could use your code sample to render out the name of the selected item (if that's really what you want to do). *Note that the content editor will use the Display Name of the items in the droplist, but your code would render out the item name. This is not a good practice as it is not possible to translate item names.
- The value is stored in Sitecore is an ID of the linked item. In this case you would need to get the selected item using this ID, then render out the required field of that item. I would probably write a code-behind method to get the selected item, then call this method within your FieldRenderer. Something like this:
Code-behind:
public Item GetLinkedItem(Item item, string itemField)
{
string dropDownItemId = item[itemField];
return Sitecore.Context.Database.GetItem(dropDownItemId);
}
Ascx markup:
<asp:Repeater ID="rptChildren" runat="server">
<ItemTemplate>
<sc:FieldRenderer ID="frTitle" runat="server" FieldName="Title" Item='<%# GetLinkedItem((Sitecore.Data.Items.Item)Container.DataItem, "YourDropLinkFieldName") %>' />
</ItemTemplate