Solved

binding to a nested repeater

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

16 Experts available now in Live!

Get 1:1 Help Now