Did you know that you can use a Sitecore item’s Children property as a datasource? Oh yes you can…
Here is a small example. First I set up a DataGrid:
<asp:gridview id="GridView" runat="server" autogeneratecolumns="false" showheader="false"> <columns> <asp:boundfield datafield="Name"> </asp:boundfield> </columns> </asp:GridView>
The Children list is a list of Sitecore.Data.Items.Item, so I can use the “Name” property as datafield. I can also use DisplayName, ID, Modifed and other fields, but I cannot use The Field property (if anyone know if this is possible please let me know).
On my Page_Load event I set up the DataSource:
Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); if (item != null) GridView.DataSource = item.Children;
Voila! A simple databound Sitecore Child list.