Objects in ItemTemplate not firing after DrillDown

3 posts, 0 answers
  1. Bryan
    Bryan avatar
    12 posts
    Member since:
    Sep 2012

    Posted 13 May 2013 Link to this post

    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??

    <%@ 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">
        <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" >
                        <table width="100%" cellpadding="0" cellspacing="0">
                            <tr align="left">
                                <td><strong>Name:</strong> <%#DataBinder.Eval(Container.DataItem, "Name")%></td>
                            <tr align="left">
                                <td><strong>Created:</strong> <%#DataBinder.Eval(Container.DataItem, "Created")%></td>
                            <tr align="right">
                                    <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>

    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
            End If
            RadOrgChart1.DataSource = GetData()
            RadOrgChart1.DataFieldID = "OrganisationId"
            RadOrgChart1.DataTextField = "Name"
            RadOrgChart1.DataFieldParentID = "ParentOrganisationId"
        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
            '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
            '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. Peter Filipov
    Peter Filipov avatar
    1028 posts

    Posted 15 May 2013 Link to this post

    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.
  3. Bryan
    Bryan avatar
    12 posts
    Member since:
    Sep 2012

    Posted 15 May 2013 Link to this post

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