Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

binding to a nested repeater

Posted on 2011-02-21
2
Medium Priority
?
495 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Integration Management Part 2
Loops Section Overview
Suggested Courses

916 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