Child object of repeater control

Pickley

New Member
Hi,<BR><BR>I have a repeater control (shown below) called rptItemList. In it, is a label called lblHeader.<BR><BR>How can I set the text of this label in code (C#)?<BR><BR>I've tried just lblHeader.Text = "whatever"; but that doesn't work, I guess because this control is a child of rptItemList but there is no obvious way to access a specific child control of the repeater object.<BR><BR>Thanks<BR>Tom<BR><BR>--------------------------------------------------------------<BR>This is how my repeater control looks:<BR>--------------------------------------------------------------<BR><asp:Repeater id=rptItemList runat="server" DataMember="TopicList" DataSource="<%# dsDataSet1 %>"><BR><HeaderTemplate><BR><asp:Label id="lblHeader" runat="server"></asp:Label><BR></HeaderTemplate><BR><ItemTemplate><BR><%# DataBinder.Eval(Container, "DataItem.Title") %></td><BR></ItemTemplate><BR></asp:Repeater><BR>--------------------------------------------------------------<BR><BR>Tom <BR><BR>Hi Tom,<BR><BR>If your repeater control has other controls, you may loop through the collection of controls like this:<BR>---------------------------------------------<BR><BR>Dim myLabel As Label<BR>Dim strLabel As String<BR><BR>For i = 0 To rptItemList.Items.Count - 1<BR><BR> myLabel = rptItemList.Items.Item(i).Controls(1)<BR> strLabel = myLabel.Text<BR><BR>Next<BR>---------------------------------------------<BR><BR>This is a way you can loop through all labels in every repeater item/alternating item. I guess you address sub controls the same way even if they're placed in the header or footer section.<BR><BR>Regards<BR>Espen Michael Lar?d<BR>(from Norway)
 
Back
Top