Adding a DataSource property to a Custom Control
To add a DataSource property to a custom control as shown in the following image, perform these steps:
- Add the Prop ID sections to your Definition.XML file.
The XML shown here is an example of a full definition file, and yours may look different.<?xml version="1.0" encoding="utf-8" ?>
<ControlType>
<FullName>CustomControlDataSourceExample.DataSourceExample, CustomControlDataSourceExample</FullName>
<Category>Listing</Category>
<Group>Custom</Group>
<Name>DataSrcEx</Name>
<DisplayName>DataSourceEx</DisplayName>
<Properties>
<Prop ID="DataSourceType" friendlyname="Type" type="complex" serverControlType="property" category="Data Source" InitializeServerControl="initializeAssociationPropertyConfig" ClearServerControl="clearComplexPropertyConfig" ServerControl="SourceCode.Forms.Controls.Web.PropertyConfiguration.AssociationPropertyConfig, SourceCode.Forms.Controls.Web" />
<Prop ID="FixedListItems" friendlyname="Items" type="string" serverControlType="property" category="Data Source" ReadOnly="true" />
<Prop ID="AssociationSO" friendlyname="SmartObject" type="string" serverControlType="smartobject" category="Data Source" ReadOnly="true" />
<Prop ID="AssociationMethod" friendlyname="Method" type="string" serverControlType="listmethod" category="Data Source" ReadOnly="true" />
<Prop ID="ValueProperty" friendlyname="Value" type="string" serverControlType="property" category="Data Source" ReadOnly="true" />
<Prop ID="DisplayTemplate" friendlyname="Display" type="string" serverControlType="property" category="Data Source" ReadOnly="true" />
</Properties>
</ControlType> - Add the get and set information shown here to your C# code file://Link to the definition file
[ControlTypeDefinition("CustomControlDataSourceExample.Definition.xml")]
public class DataSourceExample: BaseControl {
// add the following lines to your C# code in the relavant place
public string DataSourceType {
get {
return this.Attributes["DataSourceType"];
}
set {
this.Attributes["DataSourceType"] = value;
}
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer) {
writer.Write(" <b>Basic DataSource Control</b>");
}
}