Question about accessing information off server-side NodeClick event...

7 posts, 1 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 01 Jul 2009 Link to this post

    I have the following control
    <telerik:RadTreeView   
        ID="radtree" runat="server" 
        OnDataBound="radtree_DataBound" OnDataBinding="radtree_DataBinding"   
        OnNodeExpand="radtree_NodeExpand" 
        EnableEmbeddedBaseStylesheet="False" EnableEmbeddedSkins="False" 
        Skin="SomeSkin" OnNodeClick="radtree_NodeClick" 
        >      
        <CollapseAnimation Duration="100" Type="OutQuint" /> 
        <ExpandAnimation Duration="100" /> 
    </telerik:RadTreeView> 

    And here is my code behind for the event OnNodeClick:
    protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
    {  
        RadTreeView node = (RadTreeView)sender;  

    if i have defined my radtree.DataFieldID to some value is there a way in the NodeClick event to access that particular nodes DataField value?  I tried to do:
    node.DataFieldID 

    but this just returns the string of the column name not any particular unique id.

    J
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hello J,

    DataFieldID is only used for databinding purposes. You can use DataValueField instead. Then use the Value property of the node to access the associated unique value.

    protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e) 

        RadTreeNode node = e.Node;
        string value = node.Value
    }

    Greetings,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 01 Jul 2009 Link to this post

    Thank you for the reply Albert but in my NodeClick event I get an error when I do

        protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
        {  
            RadTreeNode node = (RadTreeNode)sender;  
        } 

    The error says: "Unable to cast object of type 'Telerik.Web.UI.RadTreeView' to type 'Telerik.Web.UI.RadTreeNode'.", my first thought is that I am using an 'older' version of Telerik.Web.UI.dll (2008.2.723.20 to be exact) and to update to a new dll. 

    But in the mean time, does my version support casting the sender object to a RadTreeNode instead of RadTreeView?
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hello J,

    The sender argument is the treeview which fires the NodeClick event and it cannot be cast to RadTreeNode. Use the Node property of the RadTreeNodeEventArgs argument to get the clicked node.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 01 Jul 2009 Link to this post

    Thanks again for your help Albert.  I can indeed access the node's value property when I do:

        protected void radtree_NodeClick(object sender, RadTreeNodeEventArgs e)  
        {  
            string test = e.Node.Value;  
        } 

    While it does work, I was hoping to get the pk associated with this particular node in the original DataTable.  When I set up my RadTreeView before databinding I set the following properties:
    DataSet TreeData = fnGetData();  
     
    radtree.DataTextField = "ENTITYNAME";  
    radtree.DataValueField = "ENTITYNAME";  
    radtree.DataFieldID = "PK";  
    radtree.DataFieldParentID = "PARENTPK";  
    radtree.DataSource = TreeData;  
    radtree.DataBind(); 

    See how radtree.DataFieldID is set to the value in column "PK", can RadTreeNodeEventArgs.Node access that nodes PK value on the NodeClick event?  You've shown me that it can access the column "ENTITYNAME" via the property DataValueField.

    J
  7. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hi J,

    If you configure the treeview like this:

    radtree.DataTextField = "ENTITYNAME"; 
    radtree.DataValueField = "PK"; 
    radtree.DataFieldID = "PK"; 
    radtree.DataFieldParentID = "PARENTPK"; 
    radtree.DataSource = TreeData; 
    radtree.DataBind();

    You would be able to get the primary key from the Value property.

    Sincerely yours,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 01 Jul 2009 Link to this post

    Thanks again Albert, you were right yet again!

    J
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017