Bind nested datalist to objectdatasource

G

Guest

I have a datalist (DataList1)...
with an itemtemplate...
then a table - server side (Table1)...
then another datalist (DataList2)...
another itemtemplate...
another table - server side (Table2)

DataList1 is bound to an objectdatasource (ObjectDataSource1), and has a
datakey (CategoryId). I want to bind DataList2 to another objectdatasource
(ObjectDataSource2), pulling records based on DataList1's datakey
(CategoryId).

I've set everything up, but when i run the page only DataList1 appears to
databind. Table1 renders out, but DataList2 never seems to databind.

I'm trying to do everything declaritively, is that possible? If so, what am
I doing worng?

Thanks
 
G

Guest

Make sure that the datasource for DataList2 is within the same template that
the DataList2 is placed, because for each datalist2 instance there will be an
instance of the datasource created. I have a demo that achieved the same
declaratively albeit using a parent GridView that expands a child GridView
that in turn expands a DetailsView.
http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx
 
G

Guest

Thanks for the reply. I didn't realize that the position of the
objectdatasource control mattered, but apparently it does. The only
difference here is that I wanted to do the databinding without a selection
occuring (meaning there is no SelectedIndex for me to reference). I solved
this problem by putting a Label control in the first datalist and binding the
text property to the categoryId (but made the label control hidden). Then I
used the controlparameter of the second object datasource and referenced the
text property of the label.

I read that part of the solution last night somewhere, don't remember where
as I wasn't able to get it working then (likely due to the position of the
datasource control).

All-in-all, everything seems to be working now. Thanks again for the reply,
and nice samples on your site there.

Thanks.
 

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,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top