Problem with ObjectDataSource and ITypedList

N

Norbert Ruessmann

Hello group,
I have a problem with ObjectDataSource and ITypedList.

At the end of this entry you find the implementatiopn of my List class,
derived from ArrayList and implementing ITypedList. All items contained in
the list are of type Person, which is a class derived from nothing and
implementing no Interfaces.
I put a DataSourceObject on my form and a Gridview. The DataSourceObject's
select method is GetAllPersons.

Now the problem: when running the form I see the grid with three columns for
the public properties of class Person, and the items of the list. But I do
not see this at design time.

Any help is appreciated.

Regards
Norbert Ruessmann


[DataObject(true)]
public class PersonsInArrayList : ArrayList , ITypedList
{
public PersonsInArrayList()
{
this.Add (new Person( 1 , "James" , "Cook" ));
}
public ArrayList AllPersons()
{
return this;
}

#region ITypedList Members

public PropertyDescriptorCollection
GetItemProperties(PropertyDescriptor[] listAccessors)
{
PropertyDescriptorCollection propsColl
=TypeDescriptor.GetProperties(typeof(Person));
return propsColl;
}

public string GetListName(PropertyDescriptor[] listAccessors)
{
Debug.WriteLine("PersonInArrrayList :: GetListName");
return "GrossElternCollection";
}

#endregion
}
 
W

Walter Wang [MSFT]

Hi Norbert,

You need to return a strong typed list to enable GridView to show the
column list at design time. Following is a simplest DataObject:

[DataObject(true)]
public class PersonsInArrayList
{
public IList<Person> AllPersons()
{
IList<Person> list = new List<Person>();
list.Add(new Person(1, "John", "Cook"));
return list;
}
}

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norbert Ruessmann

Thank you for the answer,

I know it is working using a list with generics. My problem is: in the past
(.NET 1.1) we developed quite a lot of business components which could be
used for data binding in Windows Forms. These components could be dragged
onto a Form, and using the designer of controls like DataGrid it was
possible to specify the data binding. These components could be used in
ASP.NET 1.1 as well --- just drag them on a page in designer and specify the
data bindings.

There were no generics in 1.1, therefore the collections used by the
components implemented interfaces like IBindingList, ITypedList and
IListSource. Thanks to ITypedList the binding mechanism of .NET was able to
know the properties of our collection items.

In NET 2.0 these components still work fine in Windows Forms -- but not in
ASP.NET since this great feature was removed in ASP.NET 2.0. Therefore I am
trying to write something like a wrapper around our components to be able
to use them with ObjectDataSource. If necessary I will even write my own
datasource control, but I do not know where to start.

I prefer to get something like ITypedList. Maybe there is some interface I
did not find in the documentation which provides the same as ITypedList in
Windows Forms for ASP.NET.

Regards
Norbert Ruessmann
Walter Wang said:
Hi Norbert,

You need to return a strong typed list to enable GridView to show the
column list at design time. Following is a simplest DataObject:

[DataObject(true)]
public class PersonsInArrayList
{
public IList<Person> AllPersons()
{
IList<Person> list = new List<Person>();
list.Add(new Person(1, "John", "Cook"));
return list;
}
}

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
 
W

Walter Wang [MSFT]

Hi Norbert,

Thanks for clarification.

Would you please sending me the code that is working correctly in .NET 1.1
(both WinForm and ASP.NET)? I will try to verify them on .NET 2.0 to see
why they stopped working on ASP.NET 2.0.

In the meanwhile, I'm currently searching in our internal database for
related documentation about the databinding changes in ASP.NET 2.0.

Thank you for your patience and understanding.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norbert Ruessmann

Hi Walter,

making some sample code will take some time, because I have to extract it
from our projects. But there are some posts on the web explaining exactly
which feature has been removed in ASP.NET 2.0.

Here are some links:
http://clariusconsulting.net/blogs/kzu/archive/2004/08/25/LosingComponents.aspx
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102242
http://www.nikhilk.net/NonVisualControlsAndComponents.aspx


In my last post I forgot to mention that our collections derived from
IBindingList, ITypedList etc. are inside a component. This component can be
dragged onto a windows form, and in APS.NET 1.1. it was possible to use it
as well.

I understand that MS removed this feature in ASP.NET 2.0, which I have to
accept . Maybe MS will introduce t again in the future, but I need a
solution quite soon.

One solution for me is that I change the collections we use to generics
(List<myType>), which seems to be quite some work. My hope with theses
postings here is, that maybe somebody knows how the ASP.NET 2 designer finds
out about the item Types in a collection during design time. The designer
will use reflection, but is the designer only able to find out about the
item Types for IList<myType>, ore are ther other possibilities? Ideal would
be an interface I have to implement.

Regards
Norbert Ruessmann
 
W

Walter Wang [MSFT]

Hi Norbert,

Thank you for telling us detailed background of this issue. I fully
understand your concerns about the ASP.NET 2.0 changes on the component
support.

The GridView's designer code calls into the data source's designer to get
the list of columns and their types, as well as some other metadata. Use
ObjectDataSource for example, it's ObjectDataSourceDesigner that provides
that data. It uses reflection to get information about the return type of
your select method. It directly handles typed DataSets, DataTables,
IEnumerable<T>, and typed Arrays. Unfortunately it doesn't handle
ITypedList.

I'm afraid the most appropriate way here is to derive from List<Person>.

Please reply here to let us know whether or not you need further
information. Thank you.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norbert Ruessmann

Hi Walter,

Thank you for the answer. In the meantime I found out how to solve my
problem --- write my own DataSourceControl including my own DataSourecView
and my own DataSourceDesigner. Thus I have full control which type
information I provide to controls like gridview.

Unfortunately there isn't too much documentation about this subject.
Especially I do not understand how to implemet RefreshSchema() in the class
derived form DataSourceDesigner. Do you have any idea where I can find it?

Apart from this lack of understanding I am optimistic that I can solve my
problem now.

Regards
Nobert Ruessmann
 
N

Norbert Ruessmann

Thanks Manuel,
this is the best information I found so far.

Regards
Norbert Rüßmann
 
W

Walter Wang [MSFT]

Hi Norbert,

I agree creating a customized Data Source control is a promising to achieve
your requirement. Please feel free to let me know if you need anything else
on this topic.

Another resource on buiding Data Source controls is:

#ScottGu's Blog : Building your own Data Source Controls in ASP.NET 2.0
http://weblogs.asp.net/scottgu/archive/2005/12/04/432319.aspx

I hope you could share your knowledge when you solved this issue; it surely
can benefit the whole community.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norbert Ruessmann

Hello Group,

basically I have my own DataSourceControl working, using the components we
developed for Windows Forms. Now I have a little problem again.

Our components can have many collections. A simple case is similar to a one
to many relation in the database. As an example take a list of orders, where
each Order has a collection of OrderItems.

If I want to display Orders and OrderItems in two GridView controls, where
the one for Orders is selectable, I have to drop two of my DataSource
controls onto the form as well, one for handling the collection of Orders,
the other one for the collection of OrderItems. No problem so far, there is
an article explaining how to do this
(http://asp.net/learn/dataaccess/tutorial10cs.aspx?tabid=63).

My problem is this: in my DataSourceControl's Select method I do not want to
select the data from the database each time and create my business objects
from the data selected, but I want to select the data once. Actually our
Components have a Fill() method, which reads all data from the database
according to some rules. These data are automatically held by our component.

Now my question: I will have one instance of my component, but two
DataSource Controls (or even more in more complex scenarios). What is the
best way to handle this?


Regards
Norbert Ruessmann
 
W

Walter Wang [MSFT]

Hi Norbert,

Based on my understanding, your current situation is:

You have one business component (which is inherited from ArrayList) and two
or more DataSource controls associated to one instance of this component.
The component is getting data from database and returns business objects
accordingly. You want the component queries database only once in one
postback for all the associated DataSource controls.

Please correct me if I've misunderstood anything.

Two associate one instance of your business component to multiple
DataSource control, your DataSource control must not use reflection to
create its own instance (like ObjectDataSource did). You need to add a
property to your DataSource controls and assign the instance of your
business component to them at runtime.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top