I want to check requested item id is a page item id or datasource item id through code. For more clarity, I have a scenario in SXA where we need to check requested id is page id or datasource id. If it is page item id then we will perform some activity or if it is datasource item id then we will perform some other activity.

3 Answers 3


You can use Sitecore.Context.Item.ID. This will return current page item ID. Use RenderingContext.Current.Rendering.Item.ID will return you the data source item ID. You can compare the ID with one of this and execute your code accordingly.

Regards, Girish

  • I am getting item id but i am not sure how to identify this is page item id or datasource item id. I am using above mentioned code but i am getting error.
    – Ashish
    Jul 1, 2020 at 17:17

I guess you are trying to identify if the datasource item is a page or just a content item. Ideally in Sitecore an item can be called a page if there is any presentation details associated with that item and this can be checked by using below code.


Above line of code will tell you if any presentation detail is associated with the item or not. If not then its a simple datasource item otherwise its a page.

Hope this helps

  • It is giving result null for the last datasource item only. However, if we have structure -: Page> Data> Test> Accordion Item> Data> Text 1 Then it is not giving the exact result. For this example the last "Text 1" showing null result. Here "Page" is a page item and other are datasource items
    – Ashish
    Jul 2, 2020 at 10:31
  • I suppose the presentation detail is only present on page item and for that you should get the layout item. But for other items like Data, Accordion Item and Text1 should give you null until you have assigned presentation detail to those items.
    – Atul Kumar
    Jul 2, 2020 at 16:51
  • i have resolved this issue by checking page template id. Thanks
    – Ashish
    Jul 3, 2020 at 10:58

Atul Kumar's answer should work for you. An alternate way is to get item by ID

Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(itemId));

and then pass the item to below func -

private bool HasPresentationDetails(Item item)
 return item.Fields[Sitecore.FieldIDs.LayoutField] != null
      && !String.IsNullOrEmpty(item.Fields[Sitecore.FieldIDs.LayoutField].Value);

If it returns true, the item is a page item. Else it is a datasource item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.