Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top