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

O

Oliver Petry

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
 
K

Kevin Yu [MSFT]

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."
 
S

Steven Cheng[MSFT]

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?= <[email protected]>
| 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: <[email protected]>
| 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
|
|
 
O

Oliver Petry

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?
 
S

Steven Cheng[MSFT]

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?= <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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?
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top