Board index » Web Programming » Tough Question: Accessing controls inside inline template in a user control, in a repeater
|
SQACSharp
|
Tough Question: Accessing controls inside inline template in a user control, in a repeater
Web Programming241
I have the following ASP.NET 2.0 code (simplified here for ease): <asp:Repeater id="SearchResultsRepeater" runat="server"> <ItemTemplate> <uc:SearchResult ID="SearchResult" ResultObject="<%#Container.DataItem%>" runat="server"> <ButtonsTemplate> <uc:ViewButton ID="ViewButton" ListingReference='<%#Eval("ListingReference")%>' runat="server" /> </ButtonsTemplate> </uc:SearchResult> </ItemTemplate> </asp:Repeater> This works fine except for the databinding on user control "ViewButton" property ListingReference. Does anyone know how to get the databinding to work in this example? For reference moving <uc:ViewButton>outside the inline template will work with no problem, but is not what I want: <asp:Repeater id="SearchResultsRepeater" runat="server"> <ItemTemplate> <uc:SearchResult ID="SearchResult" ResultObject="<%#Container.DataItem%>" runat="server" /> <ButtonsTemplate> </ButtonsTemplate> </uc:SearchResult> <uc:ViewButton ID="ViewButton" ListingReference='<%#Eval("ListingReference")%>' runat="server" /> </ItemTemplate> </asp:Repeater> I have also tried accessing <uc:ViewButton>programmatically but I don't know where to find the control: Protected Sub SearchResultsRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles SearchResultsRepeater.ItemDataBound Dim result As SearchResultObject = CType(e.Item.DataItem, SearchResultObject) If result IsNot Nothing Then Dim resultUserControl As SearchResult = CType(e.Item.FindControl("SearchResult"), SearchResult) ' FOR EXAMPLE THIS WILL NOT WORK: ' Dim viewButton As ViewButton = CType(resultUserControl.FindControl("ViewButton"), ViewButton) ' viewButton.ListingReference = result.ListingReference End If End Sub Does anyone know how I find the control in this example? Thanks! - |
