Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access a control from a detailsview programmatically?
    primarykey
    data
    text
    <p>I need to be able to modify controls from my detailsview programmatically on databind. Right now I'm using this code but I'm getting an "Index was out of range" error.</p> <pre><code>Private Sub dtlApplication_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtlApplication.DataBound Dim resumeLink As HyperLink = dtlApplication.Rows.Item(0).FindControl("lnkResume") resumeLink.NavigateUrl = "Resumes/" End Sub </code></pre> <p>I also tried this but got an "Object reference not set to an instance of an object" error.</p> <pre><code>Private Sub dtlApplication_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtlApplication.DataBound Dim resumeLink As HyperLink = dtlApplication.FindControl("lnkResume") resumeLink.NavigateUrl = "Resumes/" End Sub </code></pre> <p>I think the problem might be that the detailsview does not have any controls when the page initially loads since it doesn't get them until I select a row in my main gridview. Basically, I am trying to execute this code when I select a row in the gridview, not when the page initially loads. Could that be it? If so, where should I execute this code if not in the detailsview databound?</p> <p>Here is the detailsview and corresponding datasource markup:</p> <pre><code>&lt;asp:DetailsView ID="dtlApplication" runat="server" AutoGenerateRows="false" DataKeyNames="appID" DataSourceID="ds2" CellPadding="0" BorderColor="Transparent" BorderWidth="0px" GridLines="None" HorizontalAlign="Left" Width="459" CssClass="dtlView"&gt; &lt;Fields&gt; &lt;asp:TemplateField showheader="false"&gt; &lt;ItemTemplate&gt; &lt;h3&gt;Resume&lt;/h3&gt; &lt;asp:HyperLink runat="server" ID="lnkResume" Text="View Resume &amp;raquo;"&gt;&lt;/asp:HyperLink&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Fields&gt; &lt;PagerSettings Mode="NextPreviousFirstLast" PageButtonCount="5" FirstPageText="&amp;larr; First" LastPageText="Last &amp;rarr;" nextpagetext="Next &amp;raquo;" previouspagetext="&amp;laquo; Previous" /&gt; &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" CssClass="paging" /&gt; &lt;/asp:DetailsView&gt; &lt;asp:SqlDataSource ID="ds2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:cn %&gt;" SelectCommandType="StoredProcedure" SelectCommand="sp_SelectApplicationDetail" EnableCaching="true" CacheDuration="600"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter Name="appID" ControlID="gvAdmin" PropertyName="SelectedValue"&gt;&lt;/asp:ControlParameter&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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