views:

320

answers:

3

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.

A: 

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.

Pawel Krakowiak
Revealing the whole theory of this would take much time, and the question wasn't this, but the thing that how Microsoft guys did that. And also I am curious.
misnyo
A: 
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; }
  }
}
misnyo
A: 

You are on right way. Add set/get to CustomSettings.

adatapost
Yes, that works. The CustomSettings property only needs get, because only the MyCustomSettings properties are set, not the class itself.
misnyo