Inner Repeater without dataset relationships... is it possible?

B

Big Charles

I have inner Repeater2 inside Repeater1.
Problem is that I can't show the data of Repeater2 properly

What is shown on Screen is:

Line_1 Of Repeater_2
Line_2 Of Repeater_2
Line_3 Of Repeater_2

Line_1 Of Repeater_1
Line_2 Of Repeater_1
Line_3 Of Repeater_1

It should be:

Line_1 Of Repeater_1
Line_1 Of Repeater_2
Line_2 Of Repeater_2
Line_3 Of Repeater_2
Line_2 Of Repeater_1
Line_1 Of Repeater_2
Line_2 Of Repeater_2
Line_3 Of Repeater_2
Line_3 Of Repeater_1
Line_1 Of Repeater_2
Line_2 Of Repeater_2
Line_3 Of Repeater_2

Apparently, a nested Repeater should have been set with Relationship in
Dataset. But I bind my Repeaters with Objects!
Is there any way to show data of repeaters properly?

My code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then

Repeater1.DataSource = oMyObjectList1
Repeater1.DataBind()
End If
End Sub

Private Sub Repeater1_ItemDataBound(ByVal sender As System.Object,
ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound

Dim item As RepeaterItem = e.Item
If ((item.ItemType = ListItemType.Item) Or (item.ItemType =
ListItemType.AlternatingItem)) Then

Dim R2 As Repeater = CType(item.FindControl("Repeater2"),
Repeater)

'Dim drv As DataRowView = CType(item.DataItem, DataRowView)
R2.DataSource = oMyObjectList2
R2.DataBind()
End If
End Sub



<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td width="75%" align="right">
<%# DataBinder.Eval(Container.DataItem, "ApePat")%>
</td>
</tr>
<tr>
<td width="75%" align="right">
<%# DataBinder.Eval(Container.DataItem, "Property_1")%>
<br>
</td>
</tr>
<asp:Repeater id="Repeater2" runat="server">
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "Property_2")%>
</li>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
 
S

sloan

The key is to code up your down "GetChildren"

Here is a typical line

datasource='<%# ((DataRowView)Container.DataItem)
.Row.GetChildRows("myrelation") %>' >


.......

What I would try is this:

create a member variable
m_customers as CustomersCollection

I'm assuming that CustomersCollection has many Customer objects ('s) in it.

THEN: each Customer (object) has a child collection of Orders

Customer.Orders


When you set the .datasource property of the child repeater...... you call
your own method
Dim R2 As Repeater = CType(item.FindControl("Repeater2"),
Repeater)
dim cID as int32 = 0 '' pull the customerID from the outer
datasource
R2.DataSource = FindMyChildren ( )
R2.DataBind()

private sub FindMyChildren ( customerID as int32 ) as ''Some kind of
collectionbase object

return m_customers.Find(customerID).Orders

end sub



Does that make sense?

The key is that you need a member variable, housing all the info, and you
write you own little "GetChildren" method.

You can find some sample code at
http://sholliday.spaces.live.com/?_...ogview&_c=blogpart&partqs=amonth=5&ayear=2006
downloadable.
And find the "Find" or "Contains" method implementation
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top