Repeater problem ...

Discussion in 'ASP .Net' started by TheBurgerMan, Apr 4, 2005.

  1. TheBurgerMan

    TheBurgerMan Guest

    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?

    --
    Thanks,

    --
    TheBurgerMan, Apr 4, 2005
    #1
    1. Advertising

  2. TheBurgerMan

    TheBurgerMan Guest

    I forgot the DataSource for the ObjectB repeater, I have added it below.

    --
    Thanks,

    --
    "TheBurgerMan" <> wrote in message
    news:...
    > 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" DataSource='<%#
    > DataBinder.Eval(Container.DataItem,"ObjectBs") %>'>
    > <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?
    >
    > --
    > Thanks,
    >
    > --
    >
    >
    TheBurgerMan, Apr 4, 2005
    #2
    1. Advertising

  3. TheBurgerMan

    Karl Seguin Guest

    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!)
    "TheBurgerMan" <> wrote in message
    news:%23Io$...
    > I forgot the DataSource for the ObjectB repeater, I have added it below.
    >
    > --
    > Thanks,
    >
    > --
    > "TheBurgerMan" <> wrote in message
    > news:...
    > > 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" DataSource='<%#
    > > DataBinder.Eval(Container.DataItem,"ObjectBs") %>'>
    > > <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?
    > >
    > > --
    > > Thanks,
    > >
    > > --
    > >
    > >

    >
    >
    Karl Seguin, Apr 4, 2005
    #3
  4. TheBurgerMan

    TheBurgerMan Guest

    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
    --
    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > 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!)
    > "TheBurgerMan" <> wrote in message
    > news:%23Io$...
    >> I forgot the DataSource for the ObjectB repeater, I have added it below.
    >>
    >> --
    >> Thanks,
    >>
    >> --
    >> "TheBurgerMan" <> wrote in message
    >> news:...
    >> > 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" DataSource='<%#
    >> > DataBinder.Eval(Container.DataItem,"ObjectBs") %>'>
    >> > <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?
    >> >
    >> > --
    >> > Thanks,
    >> >
    >> > --
    >> >
    >> >

    >>
    >>

    >
    >
    TheBurgerMan, Apr 4, 2005
    #4
  5. TheBurgerMan

    Karl Seguin Guest

    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!)
    "TheBurgerMan" <> wrote in message
    news:usC$...
    > 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
    > --
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:...
    > > 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!)
    > > "TheBurgerMan" <> wrote in message
    > > news:%23Io$...
    > >> I forgot the DataSource for the ObjectB repeater, I have added it

    below.
    > >>
    > >> --
    > >> Thanks,
    > >>
    > >> --
    > >> "TheBurgerMan" <> wrote in message
    > >> news:...
    > >> > 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" DataSource='<%#
    > >> > DataBinder.Eval(Container.DataItem,"ObjectBs") %>'>
    > >> > <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?
    > >> >
    > >> > --
    > >> > Thanks,
    > >> >
    > >> > --
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Karl Seguin, Apr 4, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    841
  2. Replies:
    0
    Views:
    2,862
  3. Replies:
    1
    Views:
    7,007
    Karl Seguin
    Aug 10, 2005
  4. uncensored
    Replies:
    0
    Views:
    792
    uncensored
    Oct 25, 2006
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    190
    Microsoft
    Aug 21, 2006
Loading...

Share This Page