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

Objects in ItemTemplate not firing after DrillDown

2 Answers 78 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 13 May 2013, 10:47 AM
Hi devs,

I have built an OrgChart where the user can dynamically add items to elements of the OrgChart.

I use a LinkButton control inside the template, so that each item can have new items added to it. What I am finding is that adding items off the root object and subsequent children objects works 100% until you drill down to view the layer below. It is only then that the LinkButton stops working all together. I have also added a hyperlink to show the ID of the object to the user to confirm that the linkage is in place, and it works regardless of what layer you view.

I have attached the code below - please note that this is a sample to demonstrate the issue, but my production code is exactly the same when it comes to the core functionality.

Any thoughts??

aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="OrgChartIssue.aspx.vb" Inherits="OrgChartIssue" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel" >
            <telerik:RadOrgChart runat="server" ID="RadOrgChart1" DisableDefaultImage="true" EnableDrillDown="true" MaxDataBindDepth="2" EnableViewState="true" >
                <ItemTemplate>
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr align="left">
                            <td><strong>Name:</strong> <%#DataBinder.Eval(Container.DataItem, "Name")%></td>
                        </tr>
                        <tr align="left">
                            <td><strong>Created:</strong> <%#DataBinder.Eval(Container.DataItem, "Created")%></td>
                        </tr>
                        <tr align="right">
                            <td>
                                <asp:LinkButton runat="server" ID="lbAdd" OnCommand="lbAdd_Command" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "OrganisationId")%>'>Add</asp:LinkButton>  
                                <a href="#" onclick="alert('<%#DataBinder.Eval(Container.DataItem, "OrganisationId")%>');"  >Edit</a>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </telerik:RadOrgChart>
        </telerik:RadAjaxPanel>
 
    </form>
</body>
</html>


code behind
Public Class OrgChartIssue
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If IsNothing(Session("DemoData")) = True Then
            'set the data table up and add a default record to start with
            InitData()
        End If
 
        RadOrgChart1.DataSource = GetData()
        RadOrgChart1.DataFieldID = "OrganisationId"
        RadOrgChart1.DataTextField = "Name"
        RadOrgChart1.DataFieldParentID = "ParentOrganisationId"
        RadOrgChart1.DataBind()
    End Sub
 
    Private Function GetData() As DataTable
        'return the session object
        Return Session("DemoData")
    End Function
 
    Protected Sub lbAdd_Command(sender As Object, e As CommandEventArgs)
        'bring back the data table
        Dim Org As DataTable = DirectCast(Session("DemoData"), DataTable)
 
        'increment the key index
        Dim NextID = Org.Rows.Count + 1
 
        'add the new item
        Dim NewRec As DataRow = Org.NewRow
        NewRec.Item("OrganisationID") = NextID
        NewRec.Item("Name") = "Default New Name " & NextID
        NewRec.Item("ParentOrganisationId") = CInt(e.CommandArgument)
        NewRec.Item("Created") = Now.ToString
 
        Org.Rows.Add(NewRec)
        'put the data table back in to session
        Session("DemoData") = Org
 
        Debug.Print(String.Format("Item {0} added to parent {2} at {1}", NextID, Now.ToString, e.CommandArgument))
 
        'refresh the page
        Response.Redirect("OrgChartIssue.aspx", True)
 
    End Sub
 
    Private Sub InitData()
        Dim Org As New DataTable
 
        Org.Columns.Add("OrganisationId")
        Org.Columns.Add("Name")
        Org.Columns.Add("ParentOrganisationId")
        Org.Columns.Add("Created")
 
        'need a starting / default root object
        Org.Rows.Add("1", "Root of the Organisation", Nothing, Now.ToString)
 
        Session("DemoData") = Org
    End Sub
 
End Class

2 Answers, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 15 May 2013, 10:30 AM
Hi Bryan,

The RadOrgChart control does not have viewstate and it should be rebind on every postback. In case new Nodes are added the button Names attributes are changed on every rebind. The buttons' names are changed on every rebind and the ASP.NET is not possible to map and fire the appropriate events after a postback. That is you need to directly change the datasource data. Here is an example how it should be implemented.

Kind regards,
Peter Filipov
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
Bryan
Top achievements
Rank 1
answered on 15 May 2013, 11:24 AM
Hi Peter,

Thanks for the reply - I had initially tried the ContextMenu approach, but I took a different approach as I thought the hyperlink / template option was "cleaner".

I will re-write my screens again with the ContextMenu approach.
Tags
OrgChart
Asked by
Bryan
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or