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 ...
6 Answers, 1 is accepted
Do I have to set some property so the selected node's value is used as SelectedValue?
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.
Plamen Zdravkov
the Telerik team
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
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 ...
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.
Plamen Zdravkov
the Telerik team