检查树视图是否选择了任何节点

本文关键字:任何 节点 选择 是否 视图 检查 | 更新日期: 2023-09-27 18:33:19

我的 aspx 页上有一个树视图控件和一个按钮。在树视图节点选择的基础上,我想显示和隐藏按钮。但是当最初加载页面时,没有任何处于 if 状态的隔离节点,它正在生成异常。谁能告诉我,我怎么能找到是否有任何节点被选中?

  //Here I want to check is there any selected node "ApplicationTree.Nodes.Count>0"
         <%if(ApplicationTree.Nodes.Count>0)
               {%>                         
                            <%
//Here it is generating exception because initially no any node is selected
              IsReviewPending = view_access.IsWaitingForViewAccess(ApplicationTree.SelectedNode.Value, Session["empCode"].ToString());
              if (IsReviewPending)
              {
                  CanReviewAccess = true;
              }
              else 
              {
                  CanReviewAccess = false;
              }                    
                                      %>  
                  <%if(CanReviewAccess)
                    {%>
                <asp:Button ID="btn_Review_Access" OnClick="btn_Review_Access_Click" runat="server" BackColor="#C6304A" ForeColor="White" Text="Confirm Access Review" Width="200px"  CssClass="center3" />                 
                  <%} %>
                                 <%} %>

检查树视图是否选择了任何节点

我找到了解决方案:)

    //Here is my Code
     <%
             bool HasSelectedNode = false;
//i iterated through the overall nodes of the tree and checked any of the node is selected or not 
             for (int i = 0; i < ApplicationTree.Nodes.Count;i++ )
             {
             if(ApplicationTree.Nodes[i].Selected==true)
             {
                 HasSelectedNode = true;
             }
             }
              %>
         <%if(HasSelectedNode)
           {%>                         
                        <%
          IsReviewPending = view_access.IsWaitingForViewAccess(ApplicationTree.SelectedNode.Value, Session["empCode"].ToString());
             //  IsReviewPending = true;
          if (IsReviewPending)
          {
              CanReviewAccess = true;
          }
          else 
          {
              CanReviewAccess = false;
          }                    
                                  %>  
              <%if(CanReviewAccess)
                {%>
            <asp:Button ID="btn_Review_Access" OnClick="btn_Review_Access_Click" runat="server" BackColor="#C6304A" ForeColor="White" Text="Confirm Access Review" Width="200px"  CssClass="center3" />                 
              <%} %>
                             <%} %>