Basically, everything in Sitecore is an item. An item is a page only if it has presentation details added i.e. a valid layout and valid set of renderings.
So, when we have an item ID and if we need to find if the ID belongs to page item or a datasource, we need to get the item using the ID and then get the presentation details for the item.
This can be done easily as -
Item item = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(itemId));
item.Visualization.GetLayout(Sitecore.Context.Device);
Or 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.