Reputation: 1767
I want to add custom typed properties to a webcontrol, like for example EditRowStyle in GridView, but in a way that the property's properties can be declared in Source view in ascx/aspx. It's clear that GridView hasn't got a property like EditRowStyle-BackColor, but only EditRowStyle has. Something like this:
public class MyCustomGrid : GridView
{
[...]
private MyCustomSettings customSettings;
public MyCustomSettings CustomSettings
{
get { return customSettings; }
}
[...]
}
public class MyCustomSettings
{
private string cssClass = "default";
public string CssClass
{
get { return cssClass; }
set { cssClass = value; }
}
}
And the grid decalartion:
<c1:MyCustomGrid ID="grdCustom" runat="server" CustomSettings-CssClass="customcss" />
Because this solution doesn't work.
Upvotes: 1
Views: 2750
Reputation: 1767
public class MyCustomGrid : GridView
{
[...]
private MyCustomSettings customSettings;
[PersistenceMode(PersistenceMode.InnerProperty),DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyCustomSettings CustomSettings
{
get { return customSettings; }
}
[...]
}
[TypeConverter(typeof(MyCustomSettings))]
public class MyCustomSettings
{
private string cssClass = "default";
public string CssClass
{
get { return cssClass; }
set { cssClass = value; }
}
}
Upvotes: 1
Reputation: 10100
Why can't you just have that CssClass property in MyCustomGrid? Then it would work and be assignable via CssClass attribute in the markup. I would just add the properties to MyCustomGrid one by one, don't put them in another class.
Upvotes: 0