This is a migrated thread and some comments may be shown as answers.

RadOrgChart doesn't bind with DataTable

3 Answers 150 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Gökhan
Top achievements
Rank 1
Gökhan asked on 16 Dec 2011, 10:45 AM
I'm tring to create simple RadOrgChart page. And I have to bind it by DataTable. I did, but it doesnt work.

My Telerik version is 2011.3.1115.40.

Here is my code;
<%@ Page Title="" Language="C#" MasterPageFile="~/Controls/MasterPages/User.master" Theme="Default" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Sections_OrgChart_Default" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 
 
<telerik:RadOrgChart runat="server" ID="RadOrgChart1" ></telerik:RadOrgChart>
 
</asp:Content>

And my Cs codes,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Getron.AAM;
using Getron.AAM.EntityManagement;
using Getron.Core.Base.Objects;
using System.Data;
 
public partial class Sections_OrgChart_Default : EntityProtectedPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OrgSchema osch = new OrgSchema();
        QueryEntity qent = new QueryEntity();
        qent.QueryEntityType = Getron.Core.Enums.EQueryEntityType.WhereCondition;
        qent.Query = "SupervisorId=@SupervisorId";
        Getron.DBInterface.Parameter p0 = new Getron.DBInterface.Parameter("@SupervisorId", ParameterDirection.Input, DbType.Int64, 0);
        p0.Value = 23;
        qent.Parameters.Add(p0);
 
        DataTable dt = new DataTable();
        dt = osch.GetCustomViewAll("OrgSchemaAllData", new List<string>() { "SystemUserIntCode", "SystemUserName", "SuperVisorId" }, qent);
 
        RadOrgChart1.DataTextField = "SystemUserName";
        RadOrgChart1.DataFieldID = "SystemUserIntCode";
        RadOrgChart1.DataFieldParentID = "SupervisorId";
 
        RadOrgChart1.DataSource = dt;
        RadOrgChart1.DataBind();
    }
}

And I attached my DataTable result panel picture.(dt object preview)

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 16 Dec 2011, 01:36 PM
Hello Gökhan,

I've tested your case and found out that the problem comes from the data you're using. You have to set the SupervisorId of the root node to NULL, in order to mark it as such.

All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Hekmatullah
Top achievements
Rank 1
answered on 20 Jan 2014, 04:00 PM
this is my C# code, but it is not working, please anyone can help me.
using (SqlConnection cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myCN"].ConnectionString))
            {
                SqlCommand cmdChart = new SqlCommand("select o.UnitID,o.SupervisorID,o.IsSupervisor,u.Unit from tblOrganogram o "+
                    "inner join tblUnit u on u.ID=o.UnitID inner join tblPosition p on p.ID=o.PositionID", cn);
                cmdChart.CommandType = CommandType.Text;
                SqlCommand cmdChart1 = new SqlCommand("select o.ID,o.FirstName+' '+LastName as fullName,o.UnitID,p.Position from tblOrganogram o", cn);
                cmdChart1.CommandType = CommandType.Text;
                SqlDataAdapter adapter1 = new SqlDataAdapter();
                DataTable table1 = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter();
                DataTable table = new DataTable();

                try
                {
                    cn.Open();
                    adapter.SelectCommand = cmdChart;
                    adapter.Fill(table);
                    //Second Adapter is here.
                    adapter1.SelectCommand = cmdChart1;
                    adapter1.Fill(table1);

                    RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "UnitID";
                    RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "SupervisorID";
                    RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataGroupCollapsedField = "IsSupervisor";
                    RadOrgChart1.RenderedFields.NodeFields.Add(new Telerik.Web.UI.OrgChartRenderedField() { DataField = "Unit" });
                    RadOrgChart1.RenderedFields.NodeFields.Add(new Telerik.Web.UI.OrgChartRenderedField() { DataField = "Position" });
                    RadOrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = table;
                    //Second
                    RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "ID";
                    RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "UnitID";
                    RadOrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataTextField = "FullName";
                    RadOrgChart1.DataSource = table1;
                    RadOrgChart1.DataBind();
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                    table.Dispose();
                    table1.Dispose();

                }
0
Shinu
Top achievements
Rank 2
answered on 21 Jan 2014, 09:37 AM
Hi,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadOrgChart ID="RadOrgChart1" runat="server">
</telerik:RadOrgChart>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    String connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(connstring);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT * from Details ", conn);
    DataTable data = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(data);
    }
    finally
    {
        conn.Close();
    }
    RadOrgChart1.DataSource = data;
    RadOrgChart1.DataFieldID = "id";
    RadOrgChart1.DataFieldParentID = "parentid";
    RadOrgChart1.DataTextField = "text";
    RadOrgChart1.DataBind();
}

Hope this will helps you.
Thanks,
Shinu.
Tags
OrgChart
Asked by
Gökhan
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Hekmatullah
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or