Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.net .FindControl() and GridView returning null
    primarykey
    data
    text
    <p>I have looked over the pages on the site, but cant seem to find something general enough for my problem, so was hoping someone knows what to do. I am debugging some code someone else wrote and am having problems with a GridView statement. </p> <p>My problem is that my gridview is always null. I have a declared GridView in a panel which is in a LoginView, which is basically set up as the following.</p> <pre><code>&lt;asp:LoginView ID="LoginView1" runat="server" onviewchanged="LoginView1_ViewChanged"&gt; &lt;AnonymousTemplate&gt;&amp;nbsp;Please &lt;a href="../Default.aspx"&gt; Log In &lt;/a&gt;&lt;/AnonymousTemplate&gt; &lt;LoggedInTemplate&gt; &lt;asp:Panel ID="Panel1" runat="server"&gt; &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="2" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Horizontal" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Width="970px" OnRowCommand="GridView1_RowCommand" PageSize="40" AllowSorting="True"&gt; </code></pre> <p>After that, in a C# file, I have the following statement</p> <pre><code> GridView GridView1 = (GridView)LoginView1.FindControl("GridView1"); </code></pre> <p>When I go to run the code, I get the NullRefrenceException on GridView1. Do I need to dig down into the panel to refrence the GridView, or should I be able to access it from the main LoginView1 segment?</p> <p>Edit:Changed my code snippet to include the information for the Anonymous Template</p>
    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.
 

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