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