Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing outer repeater value from inner repeater

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
Hi,

I have nested repeaters which are working fine. The problem that I'm having is trying to display the value of the first (outer) repeater inside of the second (inner) repeater. Here is my code:

Code:
<!-- FIRST REPEATER -->
<asp:Repeater ID="rptSchools" runat="server">
      <ItemTemplate>
         <table cellspacing="0" cellpadding="0">
            <tr>
               <td class="SitePageTitle"><%# Container.DataItem("Name").ToString.Trim %></td>
            </tr>
            <tr>
               <td> 
                  <br />

<!-- SECOND REPEATER -->
                  <asp:Repeater ID="rptPortals" runat="server">
                     <ItemTemplate>
                        <table cellspacing="0" cellpadding="0">
                           <tr>
                              <td>
                                 <a href="<%# Container.DataItem("SchoolLogonURL").ToString.Trim %>">
                                    SOME TEXT HERE
                                 </a> 
                                 
<!-- VALUE FROM FIRST REPEATER -->
                                 <%# Container.DataItem("ValueFromOuterRepeaterHere").ToString.Trim %>

                              </td>
                           </tr>
                        </table>
                     </ItemTemplate>
                  </asp:Repeater>
               </td>
            </tr>
         </table>
      </ItemTemplate>
   </asp:Repeater>

This is my codebehind:

Code:
Protected Sub rptSchools_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptSchools.ItemDataBound
      Dim item As RepeaterItem = e.Item
      Dim schoolId As Object
      Dim siteCode As Object
      Dim drv As System.Data.Common.DbDataRecord = CType(item.DataItem, System.Data.Common.DbDataRecord)
      Dim rpt As Repeater = CType(item.FindControl("rptPortals"), Repeater)

      schoolId = drv("SchoolID")
      siteCode = drv("SiteCode")

      SQLCmd = "Select ..."
      dtRdr = DB.GetReader("Resources", SQLCmd)
      rpt.DataSource = dtRdr
      rpt.DataBind()
   End Sub

I bind the first repeater in my page load with a different sql statement. Is there a way to do what I'm attempting?

Please advise.
Many Thanks,
- VB Rookie
 
A quick-and-dirty solution would be to have a class-level CurrentValue field or property that you set when the parent repeater starts binding, then look to when the second repeater binds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top