Note that there are some explanatory texts on larger screens.

plurals
  1. POError setting Control Value within asp:ListView LayoutTemplate
    text
    copied!<p>So I'm really not sure what I'm doing wrong here, but my code is clearly not working. I have my list view doing everything that I need, except that when I use the <code>ListView.FindControl()</code> method, and then set a property on that control, it give me an <code>Object reference not set to an instance of an object.</code> error. Here is my code:</p> <p>ASPX</p> <pre><code>&lt;p class="rates-title"&gt;&lt;span&gt; &lt;asp:Literal ID="currentDate" runat="server"&gt;&lt;/asp:Literal&gt;&lt;/span&gt;&lt;br&gt; Todays Rates&lt;/p&gt; &lt;span class="rates-arrow sprite"&gt;&lt;/span&gt; &lt;asp:ListView ID="RatesList" ItemPlaceholderID="RSSPlaceholder" runat="server"&gt; &lt;LayoutTemplate&gt; &lt;ul&gt; &lt;asp:PlaceHolder ID="RSSPlaceholder" runat="server"&gt;&lt;/asp:PlaceHolder&gt; &lt;li&gt; &lt;asp:HyperLink ID="AllRatesLink" CssClass="all-rates" runat="server"&gt; View All Rates&lt;span&gt;&lt;/span&gt; &lt;/asp:HyperLink&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;li&gt; &lt;div class="rate-text"&gt; &lt;p&gt;&lt;%# Eval("Name") %&gt;&lt;/p&gt; &lt;div class="rate"&gt; &lt;p&gt;&lt;%# Eval("InitialRate") %&gt;%&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;%# Eval("Apr") %&gt; &lt;a href="#rates-box-&lt;%# Eval("Id") %&gt;" class="todays-rates-click-side sprite"&gt;&lt;/a&gt; &lt;div class="todays-rates-rollover"&gt; &lt;p&gt;&lt;%# Eval("ContentTruncated") %&gt;&lt;/p&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ItemTemplate&gt; &lt;/asp:ListView&gt; </code></pre> <p>Code Behind</p> <pre><code> currentDate.Text = DateTime.Now.ToString("MM.dd.yy"); HyperLink allRatesLink = (HyperLink)RatesList.FindControl("AllRatesLink"); allRatesLink.Text = "hello"; </code></pre> <p>So the weird thing is that <code>currentDate</code> works just fine, the data that I use (elsewhere in my codebehind) works just fine for iterating through the list, but as soon as I set any property on the <code>allRatesLink</code> control, it gives the object reference not set error. Any ideas/help on this one?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload