Repeater problem ...

T

TheBurgerMan

Hi all. I have an array of objects (Let's call it Object A) and each of
these objects has an array of other objects (Let's call these Object B) in
it. I can successfully repeat through Object A's and for each Object A I
can successfully repeat Object B's that are in it, like so:

Object A-1
Object B-1-A-1
Object B-2-A-1
Object B-3-A-1
Object A-2
Object B-1-A-2
Object B-2-A-2
Object A-3
Object B-1-A-3
Object B-2-A-3
etc ...

I am placing a button beside each Object B so the user can delete that
Object if they chose. My problem is that I cannot identify (in code) which
Object A the user wants to delete from? I am using the following code:

asp:Repeater ID="objectARepeater" Runat="server"
<stuff>
asp:Repeater ID="objectBRepeater" Runat="server"
<stuff>
a href="MyCode.aspx?mode=deleteObjectB&ObjectBId=<%#
DataBinder.Eval(Container.DataItem, "ObjectBId")
%>&ObjectAId='ObjectAId"><img align="absBottom" border="0" alt="Delete
ObjectB Item" src="images/delx.gif"></a
/asp:Repeater
/asp:Repeater

I have ObjectBId in the ObjectB object, but I do not store ObjectAId in the
ObjectB object, this value is in ObjectA. I need this value so I know which
ObjectA to delete the ObjectB from.

How do I reference the ObjectAId from the ObjectA while in the ObjectB
repeater?
 
K

Karl Seguin

Well, you could certainly walk up the control tree and get the parent
ItemTemplate's DataItem...ala:

<%# ((Object A)((RepeaterItem)Container.Parent.Parent).DataItem).ObjectAId%>


but that seems offly unreadable and easily breakable...why not put a
refernece to ObjectB's parant in ObjectB ?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
T

TheBurgerMan

Thanks Karl. That is the missing piece I needed. I did not want to add a
lot of references in my base objects as they could be in different parent
objects. With your code I can access the data in the sub-repeater without
adding more to my objects.

Works great.
--
Thanks,
TheBurgerMan
at
gmail.com
--
 
K

Karl Seguin

It's a pretty ugly piece of code...atleast consider using a function that
calls into better-documented codebehind:

<%# GetParentId(Container) %>

protected function GetParentId(container as RepeaterItem) as string
dim repeater as control = container.Parent
dim parentItem as RepeaterItem = ctype(repeater.Parent, RepeaterItem)
dim objecta as ObjectA = ctype(parentItem.DataItem, ObjectA)
return objecta.ObjectAId.ToString()
end function

or do something to increase the readability...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 

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

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top