Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

binding to a nested repeater

Posted on 2011-02-21
2
Medium Priority
?
492 Views
Last Modified: 2012-05-11
Hi,

I have the repeater code below which contains a nested repeater also.

To bind to the first repeater I simply use:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim groups As List(Of PaymentGroup) = Nothing

        If Not Page.IsPostBack Then
            groups = HelperReport.ExceptionsForBlankAuthInDate

            rptResults.DataSource = groups
            rptResults.DataBind()

        End If
    End Sub

This works fine.

On the PaymentGroup object however is a property Invoices which is a list(of Invoice)

I need this property to be bound to the nested repeater.

I know I would do this on the itemdatabound method of the top level repeater, but how do I reference the invoice property as I can't put it in a hidden field etc?

I don't want to go back off to the database and get it as it is a report and is likely to not run quickly over time.

Help?!
<asp:Repeater ID="rptResults" runat="server" >                                       
        <ItemTemplate>
        <tr>
            <td>                       
                <%#DataBinder.Eval(Container.DataItem, "DocRef")%>
            </td>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "Payee.Name")%>
            </td>
            <td>
                <%#DataBinder.Eval(Container.DataItem, "PaymentAmount")%>
           </td>                                                     
           <td>
                <%#DataBinder.Eval(Container.DataItem, "ProposedPaymentDate")%>
           </td>                                                     
           <td>
                <%#DataBinder.Eval(Container.DataItem, "DateAuthOut")%>
           </td>                  
           <td>
                <table>
                    <asp:Repeater ID="rptInvoices" runat="server" >                                       
                        <ItemTemplate>
                            <tr>
                                <td>                       
                                    <%#DataBinder.Eval(Container.DataItem, "InvoiceNumber")%>
                                </td>
                                <td>
                                    <%#DataBinder.Eval(Container.DataItem, "InvoiceAmount")%>
                                </td>                                                                                                           
                            </tr>            
                        </ItemTemplate>                            
                    </asp:Repeater>
                </table>
           </td>                                                                                  
        </tr>            
        </ItemTemplate>                            
    </asp:Repeater>

Open in new window

0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34941942
You are right that you use the ItemDataBound event. What you need to do is grab the item being bound from the arguments passed to the event. You can then use that to bind to the inner repeater:
    Protected Sub rptResults_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles OuterRepeater.ItemDataBound

        Dim pg As PaymentGroup = CType(e.Item.DataItem, PaymentGroup)

        Dim op As Repeater = CType(e.Item.FindControl("rptInvoices"), Repeater)
        op.DataSource = pg.Invoices        op.DataBind()

    End Sub

Open in new window

0
 

Author Comment

by:scm0sml
ID: 34941948
perfect!!

thanks for that!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question