How are custom fields in Lists modules accessed through code

Posted by Community Admin on 04-Aug-2018 19:38

How are custom fields in Lists modules accessed through code behind?

All Replies

Posted by Community Admin on 22-Aug-2011 00:00

We have created a custom field in a List called "ImageIcon".  We also have a user control imported as a custom widget called Header.ascx.  I would like to know how to access the custom field from the code behind.

Here is the code I have so far:

private void setLogoImage()
        
            String myPageName = Request.Url.Segments[Request.Url.Segments.Length - 1].Split('?')[0].ToLower();
            ListsManager manager = ListsManager.GetManager();
            Telerik.Sitefinity.Lists.Model.ListItem currentItem = manager.GetListItems()
                .Where(i => i.UrlName == myPageName)
                .FirstOrDefault();
            if (currentItem != null)
                imgMainLogo.ImageUrl = currentItem.?????
                
        

This retrieves the correct List Item.  Now, where can I get the value in my custom field?  We are currently storing the MediaUrl of the image the user selects in the "ImageIcon" field.  How are custom fields accessed through the API?

Thank you for the help.

Posted by Community Admin on 22-Aug-2011 00:00

I was able to answer my own question.  I was missing a using statement necessary for the GetValue method.

Here's my modified code:

using Telerik.Sitefinity.Model; //<---Forgot this
 
private void setLogoImage()
        
            String myPageName = Request.Url.Segments[Request.Url.Segments.Length - 1].Split('?')[0].ToLower();
            ListsManager manager = ListsManager.GetManager();
            Telerik.Sitefinity.Lists.Model.ListItem currentItem = manager.GetListItems()
                .Where(i => i.UrlName == myPageName)
                .FirstOrDefault();
            if (currentItem != null)
            
                imgMainLogo.ImageUrl = currentItem.GetValue<string>("ImageIcon");
            
        

Posted by Community Admin on 30-Aug-2013 00:00

So weird before putting 

using Telerik.Sitefinity.Model;

GetValue was an unsupported method, and it worked just after putting the reference , Thank you for highlighting it..
Thank you, 

This thread is closed