2016-02-04 93 views
0

我有一個treeview控件在我的aspx頁面和一個button.on樹視圖節點選擇的基礎上,我想顯示和隱藏button.but當最初頁面加載沒有任何選擇節點,如果條件它正在生成異常任何人都可以告訴我,我怎麼能找到有沒有選擇節點?檢查TreeView是否選擇了任何節點?

//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" />     
        <%} %> 

           <%} %> 
+0

它,因爲你正在試圖訪問該節點是空的值。可能會引入一個空檢查可以解決您的問題。我沒有上下文感知,但是如果SelectedNode爲null,您是否可能完全忽略此操作?如果是這樣介紹if(ApplicationTree.SelectedNode! - null)將解決您的問題 – Darshana

+0

不,我試過這個,但同樣的異常!感謝您的支持 –

回答

0

我找到了解決辦法:)

//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" />     
       <%} %> 

          <%} %> 
相關問題