RadOrgChart doesn't bind with DataTable

4 posts, 0 answers
  1. Gökhan
    Gökhan avatar
    11 posts
    Member since:
    Jun 2011

    Posted 16 Dec 2011 Link to this post

    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)
  2. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 16 Dec 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hekmatullah
    Hekmatullah avatar
    1 posts
    Member since:
    Dec 2013

    Posted 20 Jan 2014 Link to this post

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

                    }
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jan 2014 Link to this post

    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.
Back to Top