New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
GroupExpandCollapse
The GroupExpandCollapse is raised when a Group expand or collapse icon is clicked.
The event handler receives two parameters:
-
The instance of the orgchart firing the event
-
An event arguments parameter containing the following properties:
-
State - the state of the Node that have been expanded of collapsed.
-
SourceNode - the Node whose child group items are expanded or collapsed.
-
When this event is handled in order to make the changes persist properly the collapsed state of the node should be updated as it is shown in the sample code below:
ASPNET
<telerik:RadOrgChart RenderMode="Lightweight" runat="server" ID="RadOrgChart1" EnableCollapsing="true"
EnableGroupCollapsing="true" OnNodeExpandCollapse="RadOrgChart1_NodeExpandCollapse" OnGroupExpandCollapse="RadOrgChart1_GroupExpandCollapse">
<GroupEnabledBinding>
<NodeBindingSettings DataSourceID="NodesDataSource" DataFieldID="ID" DataFieldParentID="ParentID" DataCollapsedField="Collapsed"
DataGroupCollapsedField="GroupCollapsed" />
<GroupItemBindingSettings DataSourceID="ItemsDataSource" DataFieldID="ID" DataFieldNodeID="NodeID"
DataTextField="Text" />
</GroupEnabledBinding>
</telerik:RadOrgChart>
<asp:SqlDataSource ID="ItemsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:OrgChartExpandCollapse %>"
SelectCommand="SELECT * FROM [Items]"></asp:SqlDataSource>
<asp:SqlDataSource ID="NodesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:OrgChartExpandCollapse %>"
SelectCommand="SELECT * FROM [ExpandCollapse]"></asp:SqlDataSource>
C#
protected void RadOrgChart1_GroupExpandCollapse(object sender, OrgChartGroupExpandCollapseEventArguments e)
{
bool collapsedState = e.State == OrgChartGroupExpandCollapseState.GroupCollapsed ? true : false;
e.SourceNode.GroupCollapsed = collapsedState;
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["OrgChartExpandCollapse"].ConnectionString))
{
string updateString = @"UPDATE ExpandCollapse SET GroupCollapsed = @GroupCollapsed WHERE [ID]=" + e.SourceNode.ID;
using (SqlCommand cmd = new SqlCommand(updateString, con))
{
cmd.Parameters.Add(new SqlParameter("@GroupCollapsed", collapsedState));
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
}
}