Duplicate Group name in OrgChart

0 Answers 50 Views
OrgChart
yuki
Top achievements
Rank 2
Iron
Iron
Iron
yuki asked on 21 Apr 2023, 08:04 AM | edited on 21 Apr 2023, 11:25 AM

So I have a organization chart and a button. When I click on the button, I will fill in a DataTable stored in ViewState to be the data source of the org chart. Since I'm still having the problem in another post that nobody replied yet: Databinding keeps disappearing when post back in UI for ASP.NET AJAX | Telerik Forums  So I add some handling in Page_Load to avoid the org chart from becoming blank.

My Page logic is as follows:


<Telerik:RadButton ID="btn1" OnClick="btn_click">
...
<Telerik:RadOrgChart ID="OrgChart1">



protected DataTable table1 { get { if (ViewState["table1"] != null) return (DataTable)ViewState["table1"]; else

return null; } set { ViewState["table1"] = value; } } protected DataTable table2 { get { if (ViewState["table2"] != null) return (DataTable)ViewState["table2"]; else return null; } set { ViewState["table2"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!PostBack) // do something

if (table1 != null && table2!=null) { OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "aaa"; OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "bbb"; OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataCollapsedField = "ccc"; OrgChart1.RenderedFields.NodeFields.Add(new OrgChartRenderedField() { DataField = "A" }); OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = table1; OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "aaa"; OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "ddd"; OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataSource = table2; OrgChart1.DataBind(); } }



protected void btn_click(object sender, EventArgs e) {

               // do something to provide data for table1 and table2

                OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldID = "aaa";
                OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataFieldParentID = "bbb";
                OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataCollapsedField = "ccc";
                OrgChart1.RenderedFields.NodeFields.Add(new OrgChartRenderedField() { DataField = "A" });
                OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = table1;

                OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldNodeID = "aaa";
                OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataFieldID = "ddd";
                OrgChart1.GroupEnabledBinding.GroupItemBindingSettings.DataSource = table2;

                OrgChart1.DataBind();

}

    

And then, when the page is post back, suddenly there are duplicate group names in the org chart as you can see in the screenshot.

Can somebody help me?

Rumen
Telerik team
commented on 27 Apr 2023, 04:58 AM | edited

One possible cause for the duplication of group names could be that the orgchart is being bound to the same data source more than once. This can happen if the org chart's data source is not cleared before binding it again with new data.

To avoid this issue, you could try clearing the org chart's data source before binding it with new data in the button click event handler. You can do this by setting the data source to null before assigning the new data source. For example:

OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = null;
OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = table1;

 

Another thing to test is to wrap the  if (table1 != null && table2!=null)  statement inside the   if (!PostBack) one, which will execute it only when the page is loaded for the first time:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!PostBack)
        {

            if (table1 != null && table2 != null)
            {
                ...
                OrgChart1.DataBind();
            }
        }
    }

 

yuki
Top achievements
Rank 2
Iron
Iron
Iron
commented on 02 May 2023, 02:41 AM

Hello Rumen, thanks for answering my question. I used :

OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = null;
OrgChart1.GroupEnabledBinding.NodeBindingSettings.DataSource = table1;
 

But it didn't work, there are still duplicate group names.

As for your suggestion to put in table1 != null && table2 != null code block inside !isPostback, I cannot do that, beacuse the reason why I need to put extra databinding code for orgchart inside Page_Load() is that, my orgchart will become blank (which means datasource disappears unexpectedly) once there is a post back (see my other question in the forum: Databinding keeps disappearing when post back in UI for ASP.NET AJAX | Telerik Forums), so I manually add databinding inside Page_Load to keep the data not disappearing. 

Thanks.

Rumen
Telerik team
commented on 02 May 2023, 10:58 AM

Thank you for the update! Unfortunately, I am still unable to reproduce the issue. Can you provide a small sample with a dummy datasource that reproduces the issue?

No answers yet. Maybe you can help?

Tags
OrgChart
Asked by
yuki
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or