Findcontrol failed for templatefield (linkbutton) in detailsView
<p>I would like to set a templatefield (linkbutton) to invisible when the DetailsView is not in ReadOnly mode.  I created a linkbutton to replace the auto-gen "delete" button and want to hide it when editing and inserting.</p>

<pre><code>&lt;asp:DetailsView ID="resultDetailsView" runat="server" AutoGenerateRows="False" DataKeyNames="smo_code,id"
    DataSourceID="detailviewDataSource" Height="50px" Width="125px" OnItemInserting="resultDetailsView_ItemInserting"
    OnItemUpdating="resultDetailsView_ItemUpdating" OnItemUpdated="resultDetailsView_ItemUpdated"
    OnItemDeleted="resultDetailsView_ItemDeleted" OnItemInserted="resultDetailsView_ItemInserted"
    OnItemDeleting="resultDetailsView_ItemDeleting" OnModeChanging="resultDetailsView_ModeChanging"
    OnDataBound="resultDetailsView_DataBound" OnItemCommand="resultDetailsView_ItemCommand"&gt;
    &lt;Fields&gt;
        &lt;asp:BoundField DataField="event" HeaderText="event" SortExpression="event" /&gt;
        &lt;asp:TemplateField ShowHeader="False"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:LinkButton ID="deleteLink" runat="server" CommandName="Delete" Text="Delete"
                    OnClientClick='return confirm("Are you sure you want to delete this item?");' /&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:CommandField ShowDeleteButton="False" ShowEditButton="True" ShowInsertButton="True" /&gt;
    &lt;/Fields&gt;
&lt;/asp:DetailsView&gt;
</code></pre>

<p>IN CODE BEHIND, FINDCONTROL returned null:</p>

<pre><code>protected void resultDetailsView_DataBound(object sender, EventArgs e)
{
    LinkButton deleteLink = (LinkButton)resultDetailsView.FindControl("deleteLink");
    if (resultDetailsView.CurrentMode == DetailsViewMode.ReadOnly)
    {
        deleteLink.Visible = true;
    }
    else
    {
        deleteLink.Visible = false;
    }
 }
</code></pre>
