never show which node is selected in Postback

7 posts, 0 answers
  1. Mohamad Javad
    Mohamad Javad avatar
    39 posts
    Member since:
    Jul 2014

    Posted 10 Jul 2014 Link to this post

    hi
    when the webpage is postback the treeview , never show which, node is selected before the postback the page.
    how to save state tree view node selected, after postback page?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jul 2014 in reply to Mohamad Javad Link to this post

    Hi Mohamad Javad,

    You can store the state of RadTreeview in a session variable as follows.

    Session["myTreeView"] = rtreeDemoList.GetXml();

    And you can restore the RadTreeView state from the session variable in appropriate event like this.

    string treeViewState = (string)Session["myTreeView"];
    rtreeDemoList.LoadXmlString(treeViewState);

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mohamad Javad
    Mohamad Javad avatar
    39 posts
    Member since:
    Jul 2014

    Posted 10 Jul 2014 in reply to Shinu Link to this post

    thanks. but I've not helpful.
    how to set the special node,is selected in c# code.
    Almost like the code below is my requirement:

    RadTreeView1 . SelectedNode . Node . Value = 7 ;

    for set for example:node with value=7 is selected with click button or set this after postback page.
  5. Mohamad Javad
    Mohamad Javad avatar
    39 posts
    Member since:
    Jul 2014

    Posted 10 Jul 2014 Link to this post

    In other words, a node can click the Button, I want to get the image, and the style is different from that node by default comes in a blue..
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Jul 2014 in reply to Mohamad Javad Link to this post

    Hi Mohamad Javad,

    I guess you want to select a node in OnClick event of RadButton. Please have a look into the sample code snippet which works fine at my end. Please elaborate your requirement if it doesn't help.

    ASPX:
    <telerik:RadTreeView ID="rtreeDemoList" runat="server">
        <Nodes>
            <telerik:RadTreeNode Text="All" Value="1">
                <Nodes>
                    <telerik:RadTreeNode Text="Unread" Value="2">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Inbox" Value="3">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Sent Items" Value="4">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Deleted Items" Value="5">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="Search" Value="6">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>
    <telerik:RadButton ID="rbtnSelectItem" runat="server" Text="Select Node" OnClick="rbtnSelectItem_Click">
    </telerik:RadButton>

    C#:
    protected void rbtnSelectItem_Click(object sender, EventArgs e)
    {
        foreach (RadTreeNode parentNode in rtreeDemoList.Nodes)
        {
            foreach (RadTreeNode childNode in parentNode.Nodes)
            {
                if (childNode.Value == "6")
                    childNode.Selected = true;
            }
        }
    }

    Thanks,
    Shinu.
  7. Mohamad Javad
    Mohamad Javad avatar
    39 posts
    Member since:
    Jul 2014

    Posted 11 Jul 2014 in reply to Shinu Link to this post

    Shinu.very thanks

    ​50% of your code solved my problem.
    Now I know how I can find which node is Selected when Click the Button?
    and Save The value of node,in variable e.g. int variable.
    very thanks
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2014 in reply to Mohamad Javad Link to this post

    Hi Mohamad Javad,

    I guess you want to get the selected node value on the button click. Please have a look into the below C# code snippet to achieve your scenario.

    C#:
    protected void rbtnSelectItem_Click(object sender, EventArgs e)
    {
        int selectedValue;
        foreach (RadTreeNode parentNode in rtreeDemoList.Nodes)
        {
            if (parentNode.Selected)
            {
                selectedValue =Convert.ToInt16(parentNode.Value);
                break;
            }
            foreach (RadTreeNode childNode in parentNode.Nodes)
            {
                if (childNode.Selected)
                {
                    selectedValue = Convert.ToInt16(childNode.Value);
                    break;
                }
            }
        }
    }

    Please elaborate your requirement if it doesn't help.
    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017