我开始认为这是不可能的,所以我自己添加了这些项目。
为了将来参考其他人寻找如何做到这一点,这里是手动方式。
默认2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="TelerikTreetoProc._Default2" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scriptManager1" runat="server" />
<telerik:RadTreeView ID="treeSideBarCommands" Runat="server">
<Nodes>
<telerik:RadTreeNode runat="server" Text="Static Item A" />
<telerik:RadTreeNode runat="server" Text="Static Item B" />
<telerik:RadTreeNode runat="server" Text="Static Item C"/>
</Nodes>
</telerik:RadTreeView>
</div>
</form>
</body>
</html>
我的文件后面的代码是
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using Telerik.Web.UI;
namespace TelerikTreetoProc
{
public partial class _Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sql = "select EmployeeID, FirstName + LastName [name] from Employees";
string connString = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
using(var cn = new SqlConnection(connString ))
using(var cmd = new SqlCommand( sql, cn))
{
cn.Open();
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
RadTreeNode nd = treeSideBarCommands.Nodes[2];
while (dr.Read())
{
nd.Nodes.Add(new RadTreeNode(dr[1].ToString(), dr[0].ToString()));
}
}
}
}
}