Solved

binding to a nested repeater

Posted on 2011-02-21
2
487 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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