+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How are custom fields in Lists modules accessed through code behind?

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

3 posts, 0 answered
  1. Brad H
    Brad H avatar
    9 posts
    Registered:
    20 Aug 2009
    22 Aug 2011
    Link to this post
    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.
  2. Brad H
    Brad H avatar
    9 posts
    Registered:
    20 Aug 2009
    22 Aug 2011
    Link to this post
    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");
                }
            }
  3. Bishoy
    Bishoy avatar
    27 posts
    Registered:
    15 Aug 2013
    30 Aug 2013 in reply to Brad H
    Link to this post
    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, 
3 posts, 0 answered