How to Provide a list of DataSources and Fields at design time

Discussion in 'ASP .Net Building Controls' started by Oliver Petry, Nov 18, 2005.

  1. Oliver Petry

    Oliver Petry Guest

    I'm developing an WebControl in ASP.NET 2.0. The control inherits from
    DataBoundControl, so it can be bound to a DataSourceControl by it's
    DataSourceID property. When I declare a property with the attribute
    [TypeConverter(typeof(DataFieldConverter))] a drop down list of all fields
    (respectively columns) of the data source is shown in the designer. So far,
    so good. But this doesn't work inside a sub property.

    Here is my code. The DataContextControl contains a list of
    DataFieldPropertyCollection called Field. The DataFieldProperty has a
    property called DataPropertyName. What is necessary, to provide the drop down
    list of DataSourceControls on the page for the DataSourceID Property und a
    drop down list of fields (i.e columns) of the selected DataSource?

    [DefaultProperty("DataSourceID")]
    [ParseChildren(true, "Fields")]
    [ToolboxData("<{0}:DataContextControl
    runat=server></{0}:DataContextControl>")]
    public class DataContextControl : DataBoundControl
    {
    private DataFilterFieldPropertyCollection fields;

    public DataFilterContextControl()
    {
    this.fields = new DataFilterFieldPropertyCollection(this);
    }

    [Category("Data")]

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

    [Editor(typeof(DataFilterContextControl.DataFilterFieldPropertyCollectionEditor),
    typeof(UITypeEditor)), PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public DataFilterFieldPropertyCollection Fields
    {
    get { return fields; }
    }
    ....
    }

    public class DataFieldProperty
    {
    private string dataPropertyName;

    [Category("Data")]
    [DefaultValue("")]
    [Localizable(false)]
    [IDReferenceProperty(typeof(DataSourceControl))]
    [TypeConverter(typeof(DataSourceIDConverter))]
    public string DataSourceID
    {
    get { return dataSourceID; }
    set { dataSourceID = value; }
    }

    [NotifyParentProperty(true)]
    [TypeConverter(typeof(DataFieldConverter))]
    public string DataPropertyName
    {
    get { return dataPropertyName; }
    set { dataPropertyName = value; }
    }

    ....
    }

    Thank you,
    Oliver
    Oliver Petry, Nov 18, 2005
    #1
    1. Advertising

  2. Hi Oliver,

    We have reviewed this issue and are currently researching on it. We will
    update you ASAP. Thanks for your patience!

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."
    Kevin Yu [MSFT], Nov 19, 2005
    #2
    1. Advertising

  3. Hi Oliver,

    Welcome to ASPNET newsgroup.
    From your description, you're developing a custom databound web control
    which is wantting to utilize the new DataSourceID databinding mode in
    asp.net 2.0. Also, the custom control has a Custom Propety collection and
    the item of which will be mapped to a certain datafield of the DataSource,
    however you're getting problem when try applying the "DataFieldConverter"
    to a subproperty of your Custom Propety class (so as to retrieve datafields
    list from Custom databound control's datasource....), yes?

    Regarding on this problem, based on my research, the "DataFieldConverter"
    can retrieve a list of data fields from the current data source of a
    design-time component. So this works only for the direct Properteis of our
    custom databound control(like the DataTextField or DataValueField of
    DropDownList .... , any nested properteis in our custom property class can
    not utilize this feature (because there is not associated DataSource of the
    property's container class in that case....).

    In your scenario, I think you may need to populate your custom Property
    Class collection through some other deign-time approachs. For example, the
    SmartTag functionality in VS.NET 2005 is a good approach, you can define
    SmartTags for your custom web control through the DesignerActionList in
    VS.NET2005 design-time support.

    #Sample Control Designer with Action Lists and Services
    http://msdn2.microsoft.com/en-us/library/d0etxzd8.aspx

    #Walkthrough: Adding Smart Tags to a Windows Forms Component
    http://msdn2.microsoft.com/en-us/library/ms171829.aspx

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)


    --------------------
    | Thread-Topic: How to Provide a list of DataSources and Fields at design
    time
    | thread-index: AcXsINYbZzGl0K5JTvinAjI6jVxzPw==
    | X-WBNR-Posting-Host: 80.130.64.247
    | From: =?Utf-8?B?T2xpdmVyIFBldHJ5?= <>
    | Subject: How to Provide a list of DataSources and Fields at design time
    | Date: Fri, 18 Nov 2005 01:17:02 -0800
    | Lines: 68
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:13999
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | I'm developing an WebControl in ASP.NET 2.0. The control inherits from
    | DataBoundControl, so it can be bound to a DataSourceControl by it's
    | DataSourceID property. When I declare a property with the attribute
    | [TypeConverter(typeof(DataFieldConverter))] a drop down list of all
    fields
    | (respectively columns) of the data source is shown in the designer. So
    far,
    | so good. But this doesn't work inside a sub property.
    |
    | Here is my code. The DataContextControl contains a list of
    | DataFieldPropertyCollection called Field. The DataFieldProperty has a
    | property called DataPropertyName. What is necessary, to provide the drop
    down
    | list of DataSourceControls on the page for the DataSourceID Property und
    a
    | drop down list of fields (i.e columns) of the selected DataSource?
    |
    | [DefaultProperty("DataSourceID")]
    | [ParseChildren(true, "Fields")]
    | [ToolboxData("<{0}:DataContextControl
    | runat=server></{0}:DataContextControl>")]
    | public class DataContextControl : DataBoundControl
    | {
    | private DataFilterFieldPropertyCollection fields;
    |
    | public DataFilterContextControl()
    | {
    | this.fields = new DataFilterFieldPropertyCollection(this);
    | }
    |
    | [Category("Data")]
    |
    | [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    |
    |
    [Editor(typeof(DataFilterContextControl.DataFilterFieldPropertyCollectionEdi
    tor),
    | typeof(UITypeEditor)),
    PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    | public DataFilterFieldPropertyCollection Fields
    | {
    | get { return fields; }
    | }
    | ...
    | }
    |
    | public class DataFieldProperty
    | {
    | private string dataPropertyName;
    |
    | [Category("Data")]
    | [DefaultValue("")]
    | [Localizable(false)]
    | [IDReferenceProperty(typeof(DataSourceControl))]
    | [TypeConverter(typeof(DataSourceIDConverter))]
    | public string DataSourceID
    | {
    | get { return dataSourceID; }
    | set { dataSourceID = value; }
    | }
    |
    | [NotifyParentProperty(true)]
    | [TypeConverter(typeof(DataFieldConverter))]
    | public string DataPropertyName
    | {
    | get { return dataPropertyName; }
    | set { dataPropertyName = value; }
    | }
    |
    | ...
    | }
    |
    | Thank you,
    | Oliver
    |
    |
    Steven Cheng[MSFT], Nov 20, 2005
    #3
  4. Oliver Petry

    Oliver Petry Guest

    Thank You Steven,

    I need further assistance. My main problem is to populate the
    DataSourceControls of a page and to populate the fields (resp. columns) of a
    specific DataSource at design time. I know that this functionality is given
    by the DataBoundControl class. But I need it without deriving from
    DataBoundControl. How does DataBoundControl get these lists?
    Oliver Petry, Nov 25, 2005
    #4
  5. Hi Oliver,

    Based on my further research, if we do not derived our custom webcontrol
    from DataBoundControl, it'll be very complex to implement our own
    design-time UI for selecting and retrieving DataSource List. Many of the
    DataBoundControl's deisgn-time code use some internal interfaces and
    design-time object model which is not documented. So the recommended
    approach is making our custom webcontrol(need databinding and rich
    design-time support) derived from the DataBoundControl. Thus, we can just
    using the System.Web.UI.IDReferencePropertyAttribute to make use of the
    DataBoundControl's DesignerActionLists which can help select DataSourceID
    from given list.... e.g:


    [IDReferenceProperty(typeof(DataSourceControl))]
    public override string DataSourceID
    {
    ........................

    #The System.Web.UI.IDReferencePropertyAttribute can not work correclty
    alone without derived the control from DataBoundControl ...

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | Thread-Topic: How to Provide a list of DataSources and Fields at design
    time
    | thread-index: AcXxpnMD7cRqVvNNRnqne0e59Utcrw==
    | X-WBNR-Posting-Host: 80.130.65.46
    | From: =?Utf-8?B?T2xpdmVyIFBldHJ5?= <>
    | References: <>
    <>
    | Subject: RE: How to Provide a list of DataSources and Fields at design
    time
    | Date: Fri, 25 Nov 2005 01:56:04 -0800
    | Lines: 8
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:14039
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | Thank You Steven,
    |
    | I need further assistance. My main problem is to populate the
    | DataSourceControls of a page and to populate the fields (resp. columns)
    of a
    | specific DataSource at design time. I know that this functionality is
    given
    | by the DataBoundControl class. But I need it without deriving from
    | DataBoundControl. How does DataBoundControl get these lists?
    |
    |
    Steven Cheng[MSFT], Nov 28, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars-Erik Aabech
    Replies:
    8
    Views:
    837
    Lars-Erik Aabech
    Apr 28, 2005
  2. JT
    Replies:
    0
    Views:
    1,546
  3. =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=

    FormView and GridView with DataSources

    =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=, Feb 1, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    456
    =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=
    Feb 1, 2007
  4. flamesrock
    Replies:
    8
    Views:
    450
    Hendrik van Rooyen
    Nov 24, 2006
  5. Andy B
    Replies:
    1
    Views:
    308
    bruce barker
    May 14, 2008
Loading...

Share This Page