Last active
August 29, 2015 14:16
-
-
Save komainu85/c92b490edbc4cf34f6dc to your computer and use it in GitHub Desktop.
Auto bind Sitecore components to DataSource (Forked from Jamie Little)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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