Binding news items from Fluent? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Binding news items from Fluent?

  • Binding news items from Fluent?


  • Hi!

    Please try this.

    .Publihed().Get()
    .ToList();

    I Think Your rotator need IEnumerable for binding.
    I did the similar job and succeeded.Let me know if you get the right answer. 
    I am also new to the sitefinity. Try this I hope you will get there.
    Regards!
  • What am I doing wrong here

    protected override void CreateChildControls()
            
                base.CreateChildControls();
     
                var newsItems = App.WorkWith().NewsItems()
                                            .Where(x => ((IList<Guid>)x.GetValue("Category")).Contains(new Guid("8C4DACE0-7867-40E5-B261-E963AB672E4B")))
                                            .Publihed()
                                            .Get();
     
                this.Rotator1.DataSource = newsItems;
                this.Rotator1.DataBind();
            


    Server Error in '/' Application.

    Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MemberExpression'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MemberExpression'.

    Source Error:

    Line 38: 
    Line 39:             this.Rotator1.DataSource = newsItems;
    Line 40:             this.Rotator1.DataBind(); 
    Line 41:         
    Line 42: 

  • Thanks for the reply :)

    No dice though, same error (sadly)

    I wish there were easier fluent methods to get categories

    var newsItems = App.WorkWith().NewsItems()
                                            .InCategory("Rotator Items")
                                            .Publihed()
                                            .Get();

    ...I realize the complication though since you can have multiple "Rotator Items" categories (I believe anyway)
  • Hi,

    Please check this forum post

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/sdk/add-category-to-event.aspx


    Greetings,
    Ivan Dimitrov
    the Telerik team
  • HI Again!
    Please try the code below in itemtype you should use news item instead of Image.
    I used the following code to filter images by their category.
    If you still have some prob then let me know.

    Thanks!


     private TaxonomyPropertyDescriptor GetPropertyDescriptor(Type itemType, ITaxon taxon)
            
                return TaxonomyManager.GetPropertyDescriptor(itemType, taxon);
            


            private IEnumerable GetItems(ITaxon taxon, ContentDataProviderBase contentProvider, Type itemType)
            
                TaxonomyPropertyDescriptor prop = GetPropertyDescriptor(itemType, taxon);
                int? totalCount = 0;
                var items = contentProvider.GetItemsByTaxon(taxon.Id, prop.MetaField.IsSingleTaxon, prop.Name, itemType, "Album.Title=\"" + VehicalName + "\" and Status=\"Live\"", string.Empty, 0, 100, ref totalCount);
                return items;
            


            void GetImagesFromTaxon(Taxon objTaxon)
            
                try
                
                    var taxonomyManager = TaxonomyManager.GetManager();
                    ITaxon taxon = taxonomyManager.GetTaxon(objTaxon.Id);
                    string itemTypeName = "Telerik.Sitefinity.Libraries.Model.Image";
                    Type itemType = Telerik.Sitefinity.Utilities.TypeConverters.TypeResolutionService.ResolveType(itemTypeName);
                    var manager = Telerik.Sitefinity.Data.ManagerBase.GetMappedManager(itemType, "");
                    ContentDataProviderBase contentProvider = manager.Provider as ContentDataProviderBase;
                    IEnumerable IE = GetItems(taxon, contentProvider, itemType);


                    foreach (Telerik.Sitefinity.Libraries.Model.Image CI in IE)
                    
                        if (!IsPostBack && drp_Category.Items.FindByValue(objTaxon.Id.ToString()) == null)
                        
                            drp_Category.Items.Add(new ListItem(objTaxon.Title, objTaxon.Id.ToString()));
                        

                        imagesTag +=  CI.MediaUrl + CI.GetThumbnailUrl();
                    
                
                catch (Exception ex)
                
                    BLL.ErrorLogging("PhotoGallery => " + ex.Message);