我想使用 Telerik RAD TreeView 控件在其中显示部门和员工,如下所示:
-Dep1
--Emp1
--Emp2
-Dep2
--Emp3
-Dep3
--Emp4
--Emp5
我有 2 个表Employees 和Department 具有一对多的关系,所以DepartmentId 在两个表中。
所有在线演示都将使用自引用表显示分层数据,那么如何从 2 个连接表中实现呢?
Make your data query statement look like the hierarchical data you want to present.
Trying querying your data with a statement like:
SELECT
DeptId as Id,
NULL as ParentId,
Name
FROM
dept
UNION
SELECT
EmpID*1000 as Id,
DeptId as ParentId,
Name
FROM
Emp
Then you can bind your RadTreeView with arguments like the following:
<telerik:RadTreeView ID="RadTreeView1" runat="server" Width="100%" Height="250px"
DataSourceID="MyDataSource" DataFieldID="Id" DataFieldParentID="ParentId"
DataTextField="Name">
</telerik:RadTreeView>