Reference controls

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
 
B

bruce barker \(sqlwork.com\)

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)
 
Q

q

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.
 
S

sck10

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top