title: ASP.NET Hiding a <asp:Panel>/<th>/<tr>/<td> inside a ListView
body: <pre><code>&lt;asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="itemHolder" 
              OnItemCommand="listViewCmd" OnItemDeleting="OnItemDeleting" 
              OnItemEditing="OnItemEditing"&gt;
              &lt;LayoutTemplate&gt;
                  &lt;table class = "tblItemDetail" style = "color:Black;" width="100%" border="0" cellpadding="5"&gt;
                      &lt;tr&gt;
                          &lt;asp:Panel ID="pnlNameHead" runat="server"&gt;
                              &lt;th id="thName" runat="server"&gt;Name
                              &lt;/th&gt;   
                          &lt;/asp:Panel&gt;
                          &lt;th&gt;Address
                          &lt;/th&gt;
                          &lt;th&gt;Contact No.
                          &lt;/th&gt;
                          &lt;th&gt;E-mail Address
                          &lt;/th&gt;
                          &lt;th&gt;Edit
                          &lt;/th&gt;
                          &lt;th&gt;Delete
                          &lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;asp:PlaceHolder ID="itemHolder" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
                      &lt;/table&gt;
              &lt;/LayoutTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;tr&gt;
                      &lt;asp:Panel ID="pnlName" runat="server"&gt;
                          &lt;td align="center" id="tdName" runat="server"&gt;
                              &lt;asp:Literal ID="lit1" runat="server" Text='&lt;%# Eval("SupplierName") %&gt;'&gt;&lt;/asp:Literal&gt;
                          &lt;/td&gt;
                      &lt;/asp:Panel&gt;
                      &lt;td align="center"&gt;
                      &lt;asp:Literal ID="Literal1" runat="server" Text='&lt;%# Eval("SupplierAdd") %&gt;'&gt;&lt;/asp:Literal&gt;
                      &lt;/td&gt;
                      &lt;td align="center"&gt;
                      &lt;asp:Literal ID="Literal2" runat="server" Text='&lt;%# Eval("SupplierContact") %&gt;'&gt;&lt;/asp:Literal&gt;
                      &lt;/td&gt;
                      &lt;td align="center"&gt;
                      &lt;asp:Literal ID="Literal3" runat="server" Text='&lt;%# Eval("SupplierEmail") %&gt;'&gt;&lt;/asp:Literal&gt;
                      &lt;/td&gt;
                      &lt;td align="center"&gt;
                      &lt;asp:Button ID="Button3" runat="server" Text="Edit"  CommandArgument='&lt;%# DataBinder.Eval(Container.DataItem, "SupplierID") %&gt;' CommandName="edit" /&gt;
                      &lt;/td&gt;
                      &lt;td align="center"&gt;
                      &lt;asp:Button ID="Button2" runat="server" Text="Delete" CommandArgument='&lt;%# DataBinder.Eval(Container.DataItem, "SupplierID") %&gt;' CommandName="delete" /&gt;
                      &lt;/td&gt;                   
                  &lt;/tr&gt;
  
              &lt;/ItemTemplate&gt; 
  
          &lt;/asp:ListView&gt; 
  </code></pre>
  
  <p>I got this source code for my aspx Web Form. I'm trying to hide the column for the supplier name. I've already tried many ways like:</p>
  
  <ul>
  <li>ListView1.FindControl("pnlNameHead").Visible = false </li>
  <li>Panel pnlName = (Panel)ListView.FindControl("pnlName");
  <ul>
  <li>pnlName.Visible = false;</li>
  </ul></li>
  </ul>
  
  <p>but I always get "<strong>Object reference not set to an instance of an object</strong>". Can anyone help me please? I've been trying to figure this out for a couple of days.</p>