Query dynamic module content based on the choice field option
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
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();
using
Telerik.Sitefinity.DynamicModules;
using
Telerik.Sitefinity.Utilities.TypeConverters;
using
Telerik.Sitefinity.Data.Linq.Dynamic;