Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > How to Provide a list of DataSources and Fields at design time

Reply
Thread Tools

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

 
 
Oliver Petry
Guest
Posts: n/a
 
      11-18-2005
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}ataContextControl
runat=server></{0}ataContextControl>")]
public class DataContextControl : DataBoundControl
{
private DataFilterFieldPropertyCollection fields;

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

[Category("Data")]

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]

[Editor(typeof(DataFilterContextControl.DataFilterF ieldPropertyCollectionEditor),
typeof(UITypeEditor)), PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
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

 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      11-19-2005
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."


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-20-2005
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?= <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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.buildingc ontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:13999
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
|
| 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}ataContextControl
| runat=server></{0}ataContextControl>")]
| public class DataContextControl : DataBoundControl
| {
| private DataFilterFieldPropertyCollection fields;
|
| public DataFilterContextControl()
| {
| this.fields = new DataFilterFieldPropertyCollection(this);
| }
|
| [Category("Data")]
|
| [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
|
|
[Editor(typeof(DataFilterContextControl.DataFilterF ieldPropertyCollectionEdi
tor),
| typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
| 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
|
|

 
Reply With Quote
 
Oliver Petry
Guest
Posts: n/a
 
      11-25-2005
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?

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-28-2005
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?= <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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.buildingc ontrols
| 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.buildingc ontrols:14039
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
|
| 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?
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
acnt.com provide 2000 new computer hardware products. we provide most powerful computers on the market at reasonable prices. victoria Computer Information 0 10-11-2007 04:25 AM
FormView and GridView with DataSources =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= ASP .Net 0 02-01-2007 09:09 AM
Netbeans and Datasources JT Java 0 09-06-2006 03:12 PM
Random "The IListSource does not contain any datasources" and more (Crashing a live site at random, twice a week or so) Lars-Erik Aabech ASP .Net 8 04-28-2005 07:52 AM



Advertisments