More in this section

Forums / Developing with Sitefinity / Sitefinity 4.1 List in VB

Sitefinity 4.1 List in VB

6 posts, 0 answered
  1. andrew
    andrew avatar
    13 posts
    Registered:
    02 Jul 2012
    01 Jul 2011
    Link to this post
    Hi

    I have  a list in sitefinity which I am trying to access with a code behind  in a master template

    My list is called 'FAQ'

    My VB is
    Imports Telerik.Sitefinity.Modules.Lists
    Imports Telerik.Sitefinity.Lists.Model
     
    Public Class InsiderControl
        Inherits System.Web.UI.UserControl
     
        Public Function FindList(ByVal listTitle As String) As List
            Dim manager As ListsManager = ListsManager.GetManager()
            Dim listToLocate As List = manager.GetLists().Where(Function(l) l.Title = listTitle).[Single]()
            Return listToLocate
        End Function
     
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
     
            'Register styles
            ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "insiderControlStyles", String.Format("<link rel='stylesheet' media='screen' type='text/css' href='{0}' />", ResolveUrl("InsiderArea.css")), False)
     
            'Registers javascript/jQuery
            ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "insiderControl", String.Format("<script src='{0}' type='text/javascript'></script>", ResolveUrl("InsiderControl.js")), False)
     
            FindList("FAQ")
     
     
        End Sub
     
    End Class

    The text in bold'Manager.GetLists().Where(Function(l) l.Title = listTitle).[Single]()'
    is returning an error, when I build Im getting
    'Error    1    Overload resolution failed because no accessible 'Where' can be called with these arguments:'

    Any one any ideas where Im going wrong?

    Cheers

    Andrew
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Jul 2011
    Link to this post
    Hello Andrew,

    The Title property of built in modules is of type LString in order to support localization. While C# allows the comparing of LString with string directly in VB you have to explicitly complare the Value property of the LString type with the parameter:

    Manager.GetLists().Where(Function(l) l.Title.Value = listTitle)

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. andrew
    andrew avatar
    13 posts
    Registered:
    02 Jul 2012
    01 Jul 2011
    Link to this post
    great, thats sorted it

    Thanks
  4. andrew
    andrew avatar
    13 posts
    Registered:
    02 Jul 2012
    13 Jul 2011
    Link to this post
    or at least I thought it hade sorted the issue

    I am now getting the error
    Property 'System.String Value' is not defined for type 'System.String'

    Any ideas as to the problem here?
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    18 Jul 2011
    Link to this post
    Hello Andrew,

    Can you please check the Where statement? Are you using Title again? If you are filtering for some other field it might be declared as a string, so Value is not needed there. Please check the return type of the property. Also try to declare the filtering parameters as local variables:

    Public Function FindList(ByVal listTitle As String) As List
        Dim manager As ListsManager = ListsManager.GetManager()
        Dim titleToFind As String = listTitle
        Dim listToLocate As List = manager.GetLists().Where(Function(l) l.Title = titleToFind).[Single]()
        Return listToLocate
    End Function


    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    21 Apr 2012
    Link to this post
    Maybe try GetLists().ToList().Where....
6 posts, 0 answered