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
code behind
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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