Nested DataList Question!

G

Guest

Hi all,

With the following code in mind :

<asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%#
GetDataSource1()" Runat="server">
<ItemTemplate>
Output Value Here!
<asp:DataList ID="dlTwo" DataKeyField="myField2" DataSource="<%#
GetDataSource2(?,?)" Runat="server">
<ItemTemplate>Output Value Here!</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>

I need to send the Data Source of the nested DataList (DataSource="<%#
GetDataSource2(?,?)) two variables.

1) myField2 value of current DataList
2) myField1 value of parent DataList

Using Databinding?

Can anyone give a head on on acheiving this???

Cheers,
Adam
 
L

Laresuco

You can use the ItemDataBound event and the FindControl function to
find the second DataList, example:

Protected Sub dlOne_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlOne.ItemDataBound

CType(e.Row.FindControl("dlTwo"), DataList).DataSource =
GetDataSource2(?,?)
CType(e.Row.FindControl("dlTwo"), DataList).DataBind

End Sub

So, in the first DataList you can put a hidden label in the header with
the id of the parent DataList and in each row put the value of the
current DataList. Just check if the item is a Item, Alternate item,
header item, etc. like this:

If (e.Item.ItemType = ListItemType.Item) Then
End If

Hope this will help.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top