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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing dynamic controls within a repeater

Status
Not open for further replies.

mellenburg

Programmer
Aug 27, 2001
77
US
I have a repeater with the following code:

Code:
                <asp:Repeater ID="rpr_puf_files_doc" runat="server" DataSourceID="ods_puf_files_doc">
                    <ItemTemplate>
                        <div class="puf_files_bottomleft">
                            <%#Eval("FileLabel")%>
                        </div>
                        <div class="puf_files_bottomright">
                            <asp:Label id="lbl_puf_files_doc" runat="server"></asp:Label>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>

In the code-behind, I'm trying change the text property of lbl_puf_files_doc by looking at the controls within rpr_puf_files_doc. When I run the following code, I get a return of FALSE.

Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Trace.Warn(rpr_puf_files_doc.HasControls)

    End Sub

Why is .Net not finding the label control within the repeater. How can I access this control?
 
are you sure rpr_puf_files_doc contains data at this point? your using a datasource control which makes debugging that much more difficult, but you need to find out if your code is called before the repeater is bound. If so, this would explain why HasControls returns false.

as a general rule, the more you rely on markup (aspx) and designer code, the more difficult it is to test and debug your applications. I would recommend replacing the datasource control with actual code to query the database. This would give you control over the flow control of the Page object.

to get access the [tt]lbl_puf_files_doc[/tt] control you need to hook into the repeaters itemdatabound event. you can then do something like
Code:
var label = e.Item.FindControl("lbl_puf_files_doc") as Label;
within the handler.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Thank you Jason,

By adding an OnItemDataBound event, I'm able to see the labels.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top