Try Now
More in this section

Forums / Developing with Sitefinity / Query dynamic module content based on the choice field option

Query dynamic module content based on the choice field option

2 posts, 0 answered
  1. Anju
    Anju avatar
    19 posts
    22 Jul 2014
    05 Aug 2015
    Link to this post

    I am having a Dynamic Module - Programs By Region . There is a dropdown list of States in this module using the dynamic field type Choices. So for each item we can select a state from the dropdown. 

     Now i want to get data based on the value of the state. 

    Following is the code i used. : 

    public List<DynamicContent> GetRegionalPrograms(string region)
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(ProviderName);
                dynamicModuleManager.Provider.SuppressSecurityChecks = true;
                var regionalPrograms = dynamicModuleManager.GetDataItems(regionalprogramType).Where("State = \"" + region + "\"").ToList();
                return regionalPrograms;


    But this is not working for me. It is throwing some errors.


    Error5'System.Linq.IQueryable<Telerik.Sitefinity.DynamicModules.Model.DynamicContent>' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Queryable.Where<TSource>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,bool>>)' has some invalid arguments


    Error6Argument 2: cannot convert from 'string' to 'System.Linq.Expressions.Expression<System.Func<Telerik.Sitefinity.DynamicModules.Model.DynamicContent,bool>>


    I am not sure why this is happening. 

    Please help. 

    Thanks in advance !! 

    Anju Raman


  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    26 Oct 2016
    12 Sep 2015
    Link to this post
    Hello Anju,

    Can you please try to use the following sample code in order to filter the items by choice field value:

    dynamicModuleManager.GetDataItems(yourModuleType).Where("ChoiceFieldName.Contains(\"ChoiceFieldValue\") && Status=\"Live\"").ToList();

    Please note that you need to replace the values highlighted in yellow above with the name of your choice field and the value of the field name you would like to filter by.
    You may also refer to the below article for more details about filtering dynamic module items by dynamic field:

    Filter dynamic content items by dynamic field
    Example: Filter dynamic content items by dynamic field

    Please also note to add the following using statements:

    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.Data.Linq.Dynamic;

    Sabrie Nedzhip
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
2 posts, 0 answered