Reference controls

  • Thread starter Thread starter sck10
  • Start date Start date
S

sck10

Hello,

How do you reference a label inside a repeater? I tried the following and
got the error:

Object reference not set to an instance of an object.

((Label)this.rptRSS.FindControl("lblRSSFeed")).Text = "My Value";


<asp:Repeater id="rptRSS" runat="server">
<HeaderTemplate>
<table class="tblOutline" border="1px" style="width:99%">
<tr>
<th style="width:50%"><asp:Label id="lblRSSFeed" runat="server" /></td>
</tr>


Thanks, sck10
 
the repeater has a itemplate control for each repeated template block,
header and footer. to access a control, walk the templates until you find
the one you want (check type and whatever you used for binding), then you
can find the child control.

-- bruce (sqlwork.com)
 
Better yet... here's how to find out. Break in the ItemDataBound event
for the repeater and play with finding the control in the tree in the
immediate window. To get to the immediate window... type "immed" in
the command window.

Now when doing this at times you will want to see a parent... so you're
tree walk will look something like this.

((PlaceHolder)((MultiView)((RepeaterItem)control.FindControl("ctlMyControl")).Parent).Parent).Visible

That's just an example, but it's an example of how long it can get. If
you do any WPF work in the future, it's the same idea there too.
 
Thanks q...


q said:
Better yet... here's how to find out. Break in the ItemDataBound event
for the repeater and play with finding the control in the tree in the
immediate window. To get to the immediate window... type "immed" in
the command window.

Now when doing this at times you will want to see a parent... so you're
tree walk will look something like this.

((PlaceHolder)((MultiView)((RepeaterItem)control.FindControl("ctlMyControl")).Parent).Parent).Visible

That's just an example, but it's an example of how long it can get. If
you do any WPF work in the future, it's the same idea there too.
 
Back
Top