all groups > asp.net building controls > november 2005 >
You're in the

asp.net building controls

group:

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


How to Provide a list of DataSources and Fields at design time Oliver Petry
11/18/2005 1:17:02 AM
asp.net building controls: 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
RE: How to Provide a list of DataSources and Fields at design time v-kevy NO[at]SPAM online.microsoft.com
11/19/2005 6:05:02 AM
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."

RE: How to Provide a list of DataSources and Fields at design time stcheng NO[at]SPAM online.microsoft.com
11/20/2005 12:00:00 AM
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?= <petry@newsgroups.nospam>
| 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: <BBD3B1FF-BDF2-4707-B074-CF6549FA7D31@microsoft.com>
| 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
|
|
RE: How to Provide a list of DataSources and Fields at design time Oliver Petry
11/25/2005 1:56:04 AM
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?
RE: How to Provide a list of DataSources and Fields at design time stcheng NO[at]SPAM online.microsoft.com
11/28/2005 3:42:29 PM
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?= <petry@newsgroups.nospam>
| References: <BBD3B1FF-BDF2-4707-B074-CF6549FA7D31@microsoft.com>
<6mJjYwc7FHA.3764@TK2MSFTNGXA02.phx.gbl>
| 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: <891A5734-F1C7-4255-B25F-05AEC759A23E@microsoft.com>
| 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?
|
|
AddThis Social Bookmark Button