VS2005 DataList with Nested GridView using ObjectDataSource

S

Sam Loveridge

Hi All.

I have been loving the easy binding of a straight forward GridView directly
to a web service method using the ObjectDataSource, however I've come into a
tangle trying to apply a more complex binding solution with a DataList.

Let's say the simple method described above is a full list of items with a
customer number in a grid (call it QUERY A). What I want to do is use the
same data source for QUERY A to display a DataList that groups items by
customer details.

What I have established is a DataList that binds to a customer query to
display more detailed customer information as the primary data source for
the DataList (QUERY B), but within its ItemTemplate I want to display a
GridView for each customer to display their items. Ideally this sub query
should be based on the data from QUERY A so I don't have to load it all
again, making the switching between the full list and the grouped by
customer views faster.

This sounds like your classic master/slave query, where the data source for
the nested GridView in the DataList is driven from a value in the DataList
control for the customer ID, but how do I create a data source for my QUERY
A data to allow the funky VS2005 binding with minimal code-behind?

Any ideas?

Thanks in advance,

Sam.
 
S

Steven Cheng[MSFT]

Hello Sam,

Welcome to ASPNET newsgroup.
From your description, you're wantting to display some data on the ASP.NET
2.0 web page through the DataList control, and since those data records can
be grouped by some certain category field, you'd like to display the main
category items in the DataList and in each DataList item , use a GridView
to display those sub detailed items belong to each category value(just like
the Category/Product.... table in NorthWind...), yes? If anything I didn't
get correctly, please feel free to let me know.

Based on my understanding, the current ASP.NET 2.0 DataSource
control/DataBound control's relationship model require that the DataSource
control directly provide the records be bound to databound control, then we
declare some bound fields...
For nested databound (GridView nested in GridView or GridView nested in
DataList.....), if we still want to use declarative bound with out code, we
have to put another nested DataSource control in the primary (toplevel)
databound control's ItemTemplate... And the nested DataBound control can
be associated to that nested datasource control.........

For your scenario, if you want to reuse the Data collection return from the
webservice, and don't want additional data retrieving in each
ItemTemplate's databinding, I'm afraid we have to manually use code to fill
out different datasource from the Main datasource (retrieved from
webservice....). e.g, the webservice return a DataTable, we first
programmatically select all the distinct categories from it and bind the
categories collection with DataList, and in each ItemTemplate, we use the
category id to querty that dataset again to retrieve the products belong to
that category. Just what we also need to do in ASP.NET 1.X ...

How do you thinks of this? If you have any other ideas or question, please
feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Sam Loveridge" <[email protected]>
| Subject: VS2005 DataList with Nested GridView using ObjectDataSource
| Date: Wed, 30 Nov 2005 16:08:18 +1030
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 203.33.102.104
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:31391
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi All.
|
| I have been loving the easy binding of a straight forward GridView
directly
| to a web service method using the ObjectDataSource, however I've come
into a
| tangle trying to apply a more complex binding solution with a DataList.
|
| Let's say the simple method described above is a full list of items with
a
| customer number in a grid (call it QUERY A). What I want to do is use the
| same data source for QUERY A to display a DataList that groups items by
| customer details.
|
| What I have established is a DataList that binds to a customer query to
| display more detailed customer information as the primary data source for
| the DataList (QUERY B), but within its ItemTemplate I want to display a
| GridView for each customer to display their items. Ideally this sub query
| should be based on the data from QUERY A so I don't have to load it all
| again, making the switching between the full list and the grouped by
| customer views faster.
|
| This sounds like your classic master/slave query, where the data source
for
| the nested GridView in the DataList is driven from a value in the
DataList
| control for the customer ID, but how do I create a data source for my
QUERY
| A data to allow the funky VS2005 binding with minimal code-behind?
|
| Any ideas?
|
| Thanks in advance,
|
| Sam.
|
|
|
 
S

Sam Loveridge

Hi Steven.

Thanks for your response. Your understanding of the problem is spot on.

Yours was the answer I thought I might get. I was hoping there may be an
improved way to somehow hold the full list somehow and lay an
ObjectDataSource over the top of it to use as the source for the nested
GridView. If that's not possible then I will look to the manual coding
option you described. Is there some way I can hold a DataSet after a query
and use one of the standard DataSource objects to access it? I think there
was a DataSetDataSource in beta, but that's obviously been removed.

Sam.
 
S

Steven Cheng[MSFT]

Thanks for your response Sam,

yes, there used to have a DataSetDataSource and WebserviceDataSource,
however, since it is found that all of their funcationality can be provided
by objectdatasource which is a more common one (loose coupled with actual
datasource......), so they're not involved in the final release....

In addition, as for holding the dataset so that it can be access during the
databinding progress... , based on my experience, one common appraoch is
using the Application Cache,( the SqlDataSource's Cache is just utilizaing
the asp.net application cache...). We can generate a unique key for our
dataset and add them into application cache... Also, this is useful when
the DataSet is not changable frequently and that can also help us avoid
querying the webservice for data in each request....
Also, if you do want to cache the DataSet or make occupy the cache, you can
just use a Page variable to hold it and dispose it after databinding.....
that'll also make the dataset avaiable during all the databinding progress
of our databound control...

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



--------------------
| From: "Sam Loveridge" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: VS2005 DataList with Nested GridView using ObjectDataSource
| Date: Thu, 1 Dec 2005 08:20:05 +1030
| Lines: 16
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 203.33.102.181
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:31422
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi Steven.
|
| Thanks for your response. Your understanding of the problem is spot on.
|
| Yours was the answer I thought I might get. I was hoping there may be an
| improved way to somehow hold the full list somehow and lay an
| ObjectDataSource over the top of it to use as the source for the nested
| GridView. If that's not possible then I will look to the manual coding
| option you described. Is there some way I can hold a DataSet after a
query
| and use one of the standard DataSource objects to access it? I think
there
| was a DataSetDataSource in beta, but that's obviously been removed.
|
| Sam.
|
|
|
|
 
S

Sam Loveridge

Hi Steven.

I ended up working around the issue using the following procedure:

1) I bound the DataList control to the web service method that returns the
distinct list of Customers.

2) I edited the ItemTemplate in the DataList to bind a couple of labels,
most importantly the a label representing the key to use in the sub query
for items.

3) I added a GridView inside the ItemTemplate under the Customer labels, to
display the Items for each customer (grouped by customer).

4) I created a class in the App_Code directory with a public method
returning a DataView. This method accepts arguments that are to be passed in
from my control bindings in the DataList ItemTemplate.

5) Inside the custom class method I instantiate the web service to get the
full set of Items. Once the data is obtained from the web service, I apply a
filter to the DefaultView of the table I'm interested based on parameters to
the method (the values from the Customer binding), in and return the view of
Items

6) I then created an ObjectDataSource to deliver the DefaultView by binding
to the custom class method.

7) The ObjectDataSource for the Items to populate the GridView must be
inside the DataList ItemTemplate so that my GridView can see it when I set
its data source.

And that's it. I was still able to use the fancy pants 2.0 stuff, but had to
create my own class to act as the source for the ObjectDataSource instead of
the web service.

Thanks for your help.

Cheers,

Sam.
 
S

Steven Cheng[MSFT]

Thanks for your response Sam,

I think your current implemenation is a good idea. One thing I'm
interested is that how your nested object datasource's class reference the
main DataSet first used by the top level object datasource's class? Do you
store it in Session ,Cache or just a page scope temp variable?
Anyway, thanks again for your posting and if there're anything else we can
help later, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Sam Loveridge" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: VS2005 DataList with Nested GridView using ObjectDataSource
| Date: Fri, 2 Dec 2005 07:49:17 +1030
| Lines: 42
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 203.33.102.125
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:31468
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Hi Steven.
|
| I ended up working around the issue using the following procedure:
|
| 1) I bound the DataList control to the web service method that returns
the
| distinct list of Customers.
|
| 2) I edited the ItemTemplate in the DataList to bind a couple of labels,
| most importantly the a label representing the key to use in the sub query
| for items.
|
| 3) I added a GridView inside the ItemTemplate under the Customer labels,
to
| display the Items for each customer (grouped by customer).
|
| 4) I created a class in the App_Code directory with a public method
| returning a DataView. This method accepts arguments that are to be passed
in
| from my control bindings in the DataList ItemTemplate.
|
| 5) Inside the custom class method I instantiate the web service to get
the
| full set of Items. Once the data is obtained from the web service, I
apply a
| filter to the DefaultView of the table I'm interested based on parameters
to
| the method (the values from the Customer binding), in and return the view
of
| Items
|
| 6) I then created an ObjectDataSource to deliver the DefaultView by
binding
| to the custom class method.
|
| 7) The ObjectDataSource for the Items to populate the GridView must be
| inside the DataList ItemTemplate so that my GridView can see it when I
set
| its data source.
|
| And that's it. I was still able to use the fancy pants 2.0 stuff, but had
to
| create my own class to act as the source for the ObjectDataSource instead
of
| the web service.
|
| Thanks for your help.
|
| Cheers,
|
| Sam.
|
|
|
 

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,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top