如何使用 Teleriks RadTreeView 控件将 DataBoundItems 添加到特定节点?

发布于 2024-12-04 20:46:35 字数 500 浏览 1 评论 0原文

Teleriks RadTreeView 控件上的 AppendDataBoundItems 属性允许您将数据与静态值一起绑定。

因此,您的树可能看起来像

  • Static Item A
  • Static Item B
  • Static Item C
  • Databound Item A
  • Databound Item B
  • Databound Item C

但我希望将所有绑定值放在特定节点下,例如

  • Static Item A
  • Static Item B
  • Static Item C
    • 数据绑定项 A
    • 数据绑定项目 B
    • 数据绑定项 C

我确实意识到我可以操纵数据来实现此效果,但我不太愿意将 UI 代码移至我的存储过程中。

还有其他办法吗?

The AppendDataBoundItems property on Teleriks RadTreeView control allows you to bind data along side your static values.

So your tree might look like

  • Static Item A
  • Static Item B
  • Static Item C
  • Databound Item A
  • Databound Item B
  • Databound Item C

But I'd like to have all my bound values under a specific node, like

  • Static Item A
  • Static Item B
  • Static Item C
    • Databound Item A
    • Databound Item B
    • Databound Item C

I do realize I can manipulate the data to accomplish this effect, but I'm not comfortable moving UI code into my stored proc.

Is there any other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

闻呓 2024-12-11 20:46:35

我会让存储过程将您的数据返回到您将绑定到树视图的数据集中。一旦您获得数据集,我将操作数据集中保存的数据并将修改后的数据集绑定到您的树视图。存储过程仍在返回您的数据绑定数据,然后您就在玩中间人游戏。

I would have the stored proc return your data into the dataset that you're going to be binding to your treeview. Once you've got the dataset back, I would manipulate the data held in your dataset and bind the modified dataset to your treeview. The stored proc is still returning your databound data, and then you're playing man-in-the-middle.

哎呦我呸! 2024-12-11 20:46:35

我开始认为这是不可能的,所以我自己添加了这些项目。

以下是手动方式,供其他寻求如何执行此操作的人将来参考。

Default2.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()));
                }
            }
        }
    }
}

I'm starting to think this isn't possible, so I just added the items myself.

For future reference to anybody else looking for how to do this, here is the manual way.

Default2.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>

And my code behind file is

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()));
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文