Skip to content

Instantly share code, notes, and snippets.

@komainu85
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komainu85/c92b490edbc4cf34f6dc to your computer and use it in GitHub Desktop.
Save komainu85/c92b490edbc4cf34f6dc to your computer and use it in GitHub Desktop.
Auto bind Sitecore components to DataSource (Forked from Jamie Little)
public void BindDatasourceToSitecoreControls()
{
BindDatasourceToSitecoreControls(DataSourceItem);
}
public void BindDatasourceToSitecoreControls(Item dataSource)
{
if (Controls.Count > 0)
{
BindControls(this.Controls, dataSource);
}
}
private void BindControls(ControlCollection controls, Item dataSource)
{
foreach (Control control in controls)
{
if (control is FieldControl)
{
var fieldControl = control as FieldControl;
fieldControl.Item = dataSource;
}
if (control is FieldRenderer)
{
var fieldRenderer = control as FieldRenderer;
fieldRenderer.Item = dataSource;
}
if (control.Controls.Count > 0)
{
BindControls(control.Controls, dataSource);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment