为什么我找不到面板中继器项目?

dts*_*tsg 0 c# asp.net controls repeater panel

Object reference not set to an instance of an object当我试图找到一个Panel控件时,我一直收到错误Repeater.但其他控制措施都很好吗?谁能看到这里有什么问题?

这就是我选择控件的方式:

Panel pnlSubCategories = (Panel)e.Item.FindControl("pnlSubCategories");
Run Code Online (Sandbox Code Playgroud)

标记:

<asp:Repeater ID="rptInnerCategories" runat="server" OnItemDataBound="rptCategories_OnItemDataBound">
  <ItemTemplate>
       <li id="liCategory" runat="server">
           <asp:HyperLink ID="lnkCategory" runat="server">
                <span><asp:Literal ID="litCategory" runat="server" Visible="true" /></span>
                <asp:Image ID="imgMan" runat="server" Visible="false" /></asp:HyperLink>

                <asp:Panel ID="pnlSubCategories" runat="server" Visible="false">
                  <ul>
                     <asp:Repeater ID="rptSubCategories" runat="server" Visible="false" OnItemDataBound="rptSubCategories_OnItemDataBound">
                      <ItemTemplate>
                        <li id="liSubCategory" runat="server">
                         <asp:HyperLink ID="lnkSubCategory" runat="server">
                          <span><asp:Literal ID="litSubCategory" runat="server" /></span></asp:HyperLink>
                        </li>
                       </ItemTemplate>
                      </asp:Repeater>
                  </ul>
                 </asp:Panel>
        </li>            
   </ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

代码背后:

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
     Category category = (Category)e.Item.DataItem;
     HyperLink lnkCategory = (HyperLink)e.Item.FindControl("lnkCategory");
     Literal litCategory = (Literal)e.Item.FindControl("litCategory");
     HtmlGenericControl liCategory = (HtmlGenericControl)e.Item.FindControl("liCategory");
     Image imgMan = (Image)e.Item.FindControl("imgMan");

     Panel pnlSubCategories = (Panel)e.Item.FindControl("pnlSubCategories");
     Repeater subCategories = (Repeater)e.Item.FindControl("rptSubCategories");

     if (category.ParentCategoryId != 0)
     {
          pnlSubCategories.Visible = true; //Getting the error on this line
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

编辑*到目前为止我尝试过的内容:

Panel pnlSubCategories = (Panel)liCategory.Controls[0].FindControl("pnlSubCategories");

Panel pnlSubCategories = (Panel)liCategory.Controls[1].FindControl("pnlSubCategories");

Panel pnlSubCategories = (Panel)Page.FindControl("pnlSubCategories");

Panel pnlSubCategories = (Panel)e.Item.FindControl("pnlSubCategories");

但我仍然得到同样的错误......

编辑2*

我注释掉了Panel控件,它也找不到它Repeater subCategories下面的?这里出现了一些可怕的错误.......

编辑3*

代码背后标记

use*_*080 5

问题在于您对不同的中继器使用相同的方法.

在上次更新时,您发布了整个标记和代码,如果搜索标记,您可以rptCategories_OnItemDataBound在多个中继器上找到使用的内容:

<asp:Repeater ID="rptCategories" runat="server" OnItemDataBound="rptCategories_OnItemDataBound">
Run Code Online (Sandbox Code Playgroud)

<asp:Repeater ID="rptInnerCategories" runat="server" OnItemDataBound="rptCategories_OnItemDataBound">
Run Code Online (Sandbox Code Playgroud)