No Nodes Select

5 posts, 0 answers
  1. Herman
    Herman avatar
    28 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Please help

    I use a treeview with no checkboxes. I want a label to be visible if no node is selected.
    So if i click on a node it is highlighted then the label.visibility = false;

    How can i define that no node is selected in a treeview
  2. Herman
    Herman avatar
    28 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Something like
     

     

     

     

    if (RadTreeView2.SelectedNode.Selected == false)

     

    {

    Lbl_NonSelect.Visible =

     

    true;

     

    Lbl_NonSelect.Text =

     

    "Please select a node in the hierarchy before you click the New button";

     

     

    }

     

     

    else

     

     

     

     

     

     

    Lbl_NonSelect.Visible =

     

    false;

     

     

    }


    But it don't work
  3. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Jul 2011 Link to this post

    Hello Herman,

    I suppose you want make RadTreeview as required field. You can use the built in ASP.NET validation with RadTreeView. To validate for selected node of a treeview, just specify the ID of the tree in the ControlToValidate property of the RequiredFieldValidator.
    Here is the sample code:
    aspx:
    <telerik:RadTreeView runat="server" ID="RadTreeView1" Skin="Hay">
      <Nodes>
        <telerik:RadTreeNode runat="server" Text="Australia" Value="RootItems">
           <Nodes>
             <telerik:RadTreeNode runat="server" Text="Sidney">
             </telerik:RadTreeNode>
             <telerik:RadTreeNode runat="server" Text="Brisbane">
             </telerik:RadTreeNode>
           </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="France" Value="RootItems">
           <Nodes>
             <telerik:RadTreeNode runat="server" Text="Paris">
             </telerik:RadTreeNode>
           </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode runat="server" Text="USA" Value="RootItems">
        </telerik:RadTreeNode>
      </Nodes>
    </telerik:RadTreeView>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="RadTreeView1"
        runat="server" ErrorMessage="Please select a node in the hierarchy before you click the New button">
    </asp:RequiredFieldValidator>
    <asp:Button ID="Button1" runat="server" Text="Button" />

    Thanks,
    Princy.
  4. Herman
    Herman avatar
    28 posts
    Member since:
    Jun 2011

    Posted 06 Jul 2011 Link to this post

    Thanks for the help but it is still not working ? After you select the node and press the buton the page reloads and same message
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Jul 2011 Link to this post

    Hello Herman,

    I cannot reproduce the issue at my end. Try setting ValidationGroup and see whether that helps. Here I am pasting the full code which I tried.
    aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="validation.aspx.cs" Inherits="TreeView_validation" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
     <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     <telerik:RadTreeView runat="server" ID="RadTreeView1" Skin="Hay" ValidationGroup="treeviewValidatin">
      <Nodes>
       <telerik:RadTreeNode runat="server" Text="Australia" Value="RootItems">
        <Nodes>
         <telerik:RadTreeNode runat="server" Text="Sidney">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode runat="server" Text="Brisbane">
         </telerik:RadTreeNode>
        </Nodes>
      </telerik:RadTreeNode>
      <telerik:RadTreeNode runat="server" Text="France" Value="RootItems">
        <Nodes>
          <telerik:RadTreeNode runat="server" Text="Paris">
        </telerik:RadTreeNode>
        </Nodes>
      </telerik:RadTreeNode>
      <telerik:RadTreeNode runat="server" Text="USA" Value="RootItems">
      </telerik:RadTreeNode>
    </Nodes>
    </telerik:RadTreeView>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="RadTreeView1"
        runat="server" ErrorMessage="Please select a node in the hierarchy before you click the New button" ValidationGroup="treeviewValidatin"></asp:RequiredFieldValidator>
    <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="treeviewValidatin" />
        </div>
        </form>
    </body>
    </html>

    Thanks,
    Princy.
Back to Top