Developer forum

Forum » Development » How to set Item type from code first class

How to set Item type from code first class

Andreas Pettersson
Reply

Hi, 
I have an Item type which is going to have a field thats inherit another Item type as "Item relation List". But I can't get it to set the "Item type" of the list to my other type. 
Now I removed that Item type and configured it in admin page instead. Anyone know how to set "item type" of the list?


Replies

 
Nicolai Pedersen
Reply

Can you please share your code - and maybe also you setup from the backend of the version that you configured instead?

Thanks, Nicolai

 
Andreas Pettersson
Reply

Hi, 
I now attached a picture of my code where I have a property which should use "Ledningsgrupp" as it's itemtype on the list. My other itemtype name is "Ledningsgrupp" so I thought I just couuld create an ItemrelationListEditor field and its should be the same as the one I want to connect to. In this case "Ledningsgrupp". But maybe I miss some attribute to connect it. On picture 2 I have opened my field, but as you can see it not add my Item type "Ledningsgrupp". I also attached a picture of my "Ledningsgrupp" itemtype.

itemtype.PNG itemtype2.PNG itemtype3.PNG
 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer
Hi Andreas,
Yes, it is easy. It is better to use specialized attribute here: ItemRelationListAttribute
e.g:
        [ItemRelationList("Related news", "ExampleNewsItem")]
        [Option("Title"), Option("Subtitle"), Option("NewsType")]
        public int RelatedNews { get; set; }
or
        [ItemRelationList("Related news", nameof(ExampleNewsItem), ItemRelationListEditor.ItemListSource.Page, "Title", "Subtitle")]
        public int RelatedNews { get; set; }
 
Note: I use 'int' type for related list  properties
 
Best regards,
Vladimir
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Votes for this answer: 1
 
Andreas Pettersson
Reply

Hi,
Thanks so much for some code examples.

Regards
Andreas

 

You must be logged in to post in the forum