Solved

binding to a nested repeater

Posted on 2011-02-21
2
486 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
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP:DataGrid and how to bind to a BoundColumn 8 38
Json and asp.net mvc 2 44
How do ASP.NET and MVC work together? 4 27
Class object 2 26
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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now