TreeView SelectedValue as a filter for EntityDataSource

7 posts, 1 answers
  1. Hinek
    Hinek avatar
    6 posts
    Member since:
    Mar 2012

    Posted 02 Apr 2012 Link to this post

    I'm trying to use TreeView and GridView with Entity Framework. I have a page with one TreeView, one GridView, each with it's own EntityDataSource. This far it's working.
    Now I want to filter the data in the grid, so I configure the Where property of it's datasource to filter where it.CategoryID = @CategoryID. And I bind the parameter @CategoryID to the TreeView.SelectedValue. This doesn't work: All items are shown in the grid regardless which category I select in the tree. :(
    If I replace the TreeView with a ComboBox, the filter works ...
  2. Hinek
    Hinek avatar
    6 posts
    Member since:
    Mar 2012

    Posted 04 Apr 2012 Link to this post

    I just noticed: If I set a default value for the parameter, the GridView is filtered correctly by this value. But it never changes regardless of which node I select in the TreeView.
    Do I have to set some property so the selected node's value is used as SelectedValue?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 05 Apr 2012 Link to this post

    Hi Hinek,

     
    In RadTreeView the SelectedValue property is returning the value of the selected node. You can handle the NodeClick event of RadTreeView and filter the RadGrid according to the clicked node.

    Hope this will be helpful.

    Kind regards,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Hinek
    Hinek avatar
    6 posts
    Member since:
    Mar 2012

    Posted 10 Apr 2012 Link to this post

    So a "selected node" in RadTreeView means a checked node? Isn't this a bit uncommon? In the most controls (including the standard .NET controls) the selected node is the one node that's highlighted. Or am I mistaken?
  6. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 11 Apr 2012 Link to this post

    Hi Hinek, 

     
    It seems that there is some kind of misunderstanding. Please excuse me for that.

    Let me clear the behavior of RadTreeView. The selected node is the one that is clicked on or navigated with keyboard to, not the one that is checked. A node is highlighted when the mouse is positioned over it but it is not selected. You can refer to some of our on-line demos where this behavior can be observed.

    As for you scenario would you please elaborate at which event are you trying to get the value of the Selected node because it is not very clear what is not working properly. Here is one way to get it on a click of a button:

    <telerik:RadButton runat="server" ID="RB" OnClick="RB_Click">
            </telerik:RadButton>
            <telerik:RadTreeView runat="server" ID="RTV">
                <Nodes>
                    <telerik:RadTreeNode Text="a" Value="1">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="b" Value="2">
                    </telerik:RadTreeNode>
                    <telerik:RadTreeNode Text="c" Value="3">
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeView>
    protected void RB_Click(object sender, EventArgs e)
        {
            Response.Write(RTV.SelectedValue);
        }

    Here you can the video of my test. 
     
    Hope this will be helpful.

    Kind regards,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Hinek
    Hinek avatar
    6 posts
    Member since:
    Mar 2012

    Posted 11 Apr 2012 Link to this post

    Hi, thanks for the quick reply. I guess we talked past each other. Ok, so when I click a node it is the selected node, that's great, because this is the behaviour I was expecting.
    So I guess my problem is the EntityDataSource doesn't notice, that SelectedValue has changed. When I use RadComboBox, the EntityDataSource notices automatically when a new value was chosen (drop-down opened, clicked on a value) and refreshes it's filter. But with the RadTreeView, the EntityDataSource does not react to the change when a node is clicked-->selected.
    I'm not sure how EntityDataSource manages stuff like this, it just that it works with the RadComboBox but not with the RadTreeView which is perplexing to me ...
  8. Answer
    Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 16 Apr 2012 Link to this post

    Hello Hinek,

     
    RadCombobox and RadTreeView are quire different controls and it is expected that sometimes a scenario that is working properly with one of them by design is not working with the other one. In your case I would recommend you to try to rebind the RadGrid according to the node's value in the onNodeClick server event.

     If this doesn't help please share the code that is working properly with RadCombobox so we can review it and try to provide you with a possible workaround with RadTreeView.

    Greetings,
    Plamen Zdravkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017