RadDockZone1.Docks.Sort(Function(dock1 As RadDock, dock2 As RadDock) dock1.Index.CompareTo(dock2.Index))
For Each dock As RadDock In RadDockZone1.Docks
For Each control As Control In dock.ContentContainer.Controls(0).Controls
If (TypeOf control Is CheckBox) Then
checkBox = CType(control, CheckBox)
If checkBox.Checked Then
selectedWebParts.Add(dock.ID)
End If
End If
Next
Next
I have a RadDockZone in which i am adding docks at runtime.
User can drap and drop any dock and can change their position in RadDockZone.
Now on postback, I am trying to get the docks from Raddockzone ordered be Dock index.
I am using the above code but it is not working the way I want.
Could you please help me to get the docks from Raddockzone ordered by their index.
7 Answers, 1 is accepted
0
Hello Deepak,
When the docks are placed in the zone they are already ordered by their index, that is, if the dock is placed at the third position, and then moved to the top of the stack, its index automatically becomes zero. Moreover the Sort method of the DockCollection object is sorting the docks by their index in the correct way. The following project has four docks in a zone with four different skins. After the docks are sorted the skins are displayed in a Label in the way they appear in the dock zone. Here is the full source code:
.aspx
.cs
Greetings,
Pero
the Telerik team
When the docks are placed in the zone they are already ordered by their index, that is, if the dock is placed at the third position, and then moved to the top of the stack, its index automatically becomes zero. Moreover the Sort method of the DockCollection object is sorting the docks by their index in the correct way. The following project has four docks in a zone with four different skins. After the docks are sorted the skins are displayed in a Label in the way they appear in the dock zone. Here is the full source code:
.aspx
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!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
id
=
"Head1"
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
<
Scripts
>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
</
Scripts
>
</
asp:ScriptManager
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Sort Docks"
OnClick
=
"Button1_Click"
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
ForeColor
=
"Red"
></
asp:Label
>
<
div
>
<
telerik:RadDockLayout
ID
=
"RadDockLayout1"
runat
=
"server"
>
<
telerik:RadDockZone
ID
=
"RadDockZone1"
runat
=
"server"
MinHeight
=
"300px"
Width
=
"300px"
>
<
telerik:RadDock
ID
=
"RadDock1"
runat
=
"server"
Title
=
"Default"
Width
=
"300px"
>
<
ContentTemplate
>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
CONTENT
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
</
ContentTemplate
>
</
telerik:RadDock
>
<
telerik:RadDock
ID
=
"RadDock2"
runat
=
"server"
Title
=
"Black"
Width
=
"300px"
Skin
=
"Black"
>
<
ContentTemplate
>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
CONTENT
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
</
ContentTemplate
>
</
telerik:RadDock
>
<
telerik:RadDock
ID
=
"RadDock3"
runat
=
"server"
Title
=
"Sunset"
Width
=
"300px"
Skin
=
"Sunset"
>
<
ContentTemplate
>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
CONTENT
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
</
ContentTemplate
>
</
telerik:RadDock
>
<
telerik:RadDock
ID
=
"RadDock4"
runat
=
"server"
Title
=
"Hay"
Width
=
"300px"
Skin
=
"Hay"
>
<
ContentTemplate
>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
CONTENT
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
</
ContentTemplate
>
</
telerik:RadDock
>
</
telerik:RadDockZone
>
</
telerik:RadDockLayout
>
</
div
>
</
form
>
</
body
>
</
html
>
.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.Web.Caching;
public
partial
class
Default_Dock : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
Label1.Text =
""
;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
RadDockZone1.Docks.Sort(CompareDocks);
foreach
(RadDock dock
in
RadDockZone1.Docks)
{
Label1.Text +=
" "
+ dock.Skin;
}
}
private
static
int
CompareDocks(RadDock x, RadDock y)
{
return
x.Index.CompareTo(y.Index);
}
}
Greetings,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Martin Roussel
Top achievements
Rank 1
answered on 03 Jan 2013, 04:01 PM
Hi, I have a related issue in the sense that my RadDockLayout server-side function "GetRegisteredDocksState()" is not always returning the DockState List in the index order. To do so, I have to apply a sort method myself in order to load my dynamic docks at runtime in the order they should be. Does the function supposed to garantee its List ordering?
here is the an example output of the function I get (this time was after moving one of the dock):
here is how I sort it (for those it may help):
TIA
Martin
here is the an example output of the function I get (this time was after moving one of the dock):
?RadDockLayout1.GetRegisteredDocksState()
Count = 2
[0]: {
"UniqueName"
:
"44700539a2e60a4165a9758a6b5683194283"
,
"DockZoneID"
:
"Dashboard_2_1706aecdae239a4853ab211a1087e0d2b244_uc_RadDockZone1"
,
"Width"
:
"300px"
,
"Height"
:
""
,
"ExpandedHeight"
:
"0"
,
"Top"
:
"0px"
,
"Left"
:
"0px"
,
"Resizable"
:
"False"
,
"Closed"
:
"False"
,
"Collapsed"
:
"False"
,
"Pinned"
:
"False"
,
"Title"
:
"Details"
,
"Text"
:
"SIDET"
,
"Tag"
:
"ucSIHomeDetails.ascx"
,
"Index"
:
"1"
}
[1]: {
"UniqueName"
:
"1c5ba4d0ae652a4373ab5f5a5980d94ede76"
,
"DockZoneID"
:
"Dashboard_2_1706aecdae239a4853ab211a1087e0d2b244_uc_RadDockZone1"
,
"Width"
:
"300px"
,
"Height"
:
""
,
"ExpandedHeight"
:
"0"
,
"Top"
:
"0px"
,
"Left"
:
"0px"
,
"Resizable"
:
"False"
,
"Closed"
:
"False"
,
"Collapsed"
:
"False"
,
"Pinned"
:
"False"
,
"Title"
:
"Comments"
,
"Text"
:
"SICOM"
,
"Tag"
:
"ucSIHomeComments.ascx"
,
"Index"
:
"0"
}
here is how I sort it (for those it may help):
private
void
SetDockOrder(
ref
List<DockState> statelist)
{
statelist = statelist.OrderBy(x => x.Index).ToList();
}
TIA
Martin
0
Hello Martin,
Please check step 5.2 from the Example section of the help article Dynamically Creating RadDock Controls and the online demo Dynamically Created Docks. Sorting the docks state list is not required as the Index property of every RadDock is stored and it can be initialized via the RadDock.ApplyState method, which is called when recreating the docks on Page_Init.
I hope this helps. Feel free to contact us again if you encounter more difficulties.
All the best,
Slav
the Telerik team
Please check step 5.2 from the Example section of the help article Dynamically Creating RadDock Controls and the online demo Dynamically Created Docks. Sorting the docks state list is not required as the Index property of every RadDock is stored and it can be initialized via the RadDock.ApplyState method, which is called when recreating the docks on Page_Init.
I hope this helps. Feel free to contact us again if you encounter more difficulties.
All the best,
Slav
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
Martin Roussel
Top achievements
Rank 1
answered on 04 Jan 2013, 06:30 PM
Slav, something should be wrong with my ApplyState then since I have the following and I obtain ucB.ascx on top of ucA.ascx despite their index (the reason I use my sort function):
If I understand correctly, the Index 0 (A) should be automatically positionned on top of Index 1 (B).
UPDATE: The code above is located into a user control that I use in a RadTabStrip/RadMultiPage. If I put the code in a normal aspx page and use it outside the RadTabStrip, the ordering becomes good (Index 0 on top). Can you please try it in a RadTabStrip (as a user control) and let me know?
TIA
Martin
protected
void
Page_Init(
object
sender, EventArgs e)
{
GetDockStates();
//Immediate Window (VS) gives me this at this exact line:
?CurrentDockStates
Count = 2
[0]: {
"UniqueName"
:
"44700539a2e60a4165a9758a6b5683194283"
,
"DockZoneID"
:
"Dashboard_2_aec97e7fac761a466fa9577afa523920cefa_uc_RadDockZone1"
,
"Width"
:
"300px"
,
"Height"
:
""
,
"ExpandedHeight"
:
"0"
,
"Top"
:
"0px"
,
"Left"
:
"0px"
,
"Resizable"
:
"False"
,
"Closed"
:
"False"
,
"Collapsed"
:
"False"
,
"Pinned"
:
"False"
,
"Title"
:
"B"
,
"Text"
:
"B"
,
"Tag"
:
"ucB.ascx"
,
"Index"
:
"1"
}
[1]: {
"UniqueName"
:
"aef5c9bda73a5a4780a8181a776539919ff2"
,
"DockZoneID"
:
"Dashboard_2_aec97e7fac761a466fa9577afa523920cefa_uc_RadDockZone1"
,
"Width"
:
"300px"
,
"Height"
:
""
,
"ExpandedHeight"
:
"0"
,
"Top"
:
"0px"
,
"Left"
:
"0px"
,
"Resizable"
:
"False"
,
"Closed"
:
"False"
,
"Collapsed"
:
"False"
,
"Pinned"
:
"False"
,
"Title"
:
"A"
,
"Text"
:
"A"
,
"Tag"
:
"ucA.ascx"
,
"Index"
:
"0"
}
//Recreate the docks in order to ensure their proper operation
for
(
int
i = 0; i < CurrentDockStates.Count; i++)
{
RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);
RadDockLayout1.Controls.Add(dock);
LoadWidget(dock, CurrentDockStates[i].Text, CurrentDockStates[i].Title);
if
(CurrentDockStates[i].Closed ==
true
)
{
dock.Visible =
false
;
}
}
}
private
RadDock CreateRadDockFromState(DockState state)
{
RadDock dock =
new
RadDock();
dock.DockMode = DockMode.Docked;
dock.Resizable =
false
;
dock.ID =
string
.Format(
"RadDock{0}"
, state.UniqueName);
//set RadDockZone ID
state.DockZoneID = RadDockZone1.ClientID;
dock.ApplyState(state);
dock.Commands.Add(
new
DockCloseCommand());
dock.Commands.Add(
new
DockExpandCollapseCommand());
return
dock;
}
private
void
LoadWidget(RadDock dock,
string
strWidgetCode,
string
strWidgetName)
{
try
{
if
((
string
.IsNullOrEmpty(dock.Tag) && strWidgetCode ==
""
) || dock.Closed)
{
return
;
}
Control widget =
null
;
switch
(strWidgetCode)
{
case
"A"
:
dock.Tag =
"ucA.ascx"
;
widget = LoadControl(dock.Tag);
break
;
case
"B"
:
dock.Tag =
"ucB.ascx"
;
widget = LoadControl(dock.Tag);
break
;
default
:
if
(dock.Tag !=
null
)
{
widget = LoadControl(dock.Tag);
}
break
;
}
dock.Text = strWidgetCode;
dock.Title = strWidgetName;
dock.ContentContainer.Controls.Add(widget);
}
catch
{
//do nothing
}
}
protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e)
{
foreach (DockState state in CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
class
=
"DockContainerPanel"
>
<
telerik:RadDockLayout
runat
=
"server"
ID
=
"RadDockLayout1"
OnSaveDockLayout
=
"RadDockLayout1_SaveDockLayout"
OnLoadDockLayout
=
"RadDockLayout1_LoadDockLayout"
>
<
telerik:RadDockZone
runat
=
"server"
ID
=
"RadDockZone1"
CssClass
=
"DockZone"
Orientation
=
"vertical"
>
</
telerik:RadDockZone
>
</
telerik:RadDockLayout
>
</
asp:Panel
>
If I understand correctly, the Index 0 (A) should be automatically positionned on top of Index 1 (B).
UPDATE: The code above is located into a user control that I use in a RadTabStrip/RadMultiPage. If I put the code in a normal aspx page and use it outside the RadTabStrip, the ordering becomes good (Index 0 on top). Can you please try it in a RadTabStrip (as a user control) and let me know?
TIA
Martin
0
Hi Martin,
The code samples you posted appear to be correct. If you add the user control that contains the RadDocks in code-behind, you must do so in any of the events that take place before LoadDockLayout to ensure that the stored state will be applied correctlu. The Page.Init event is perfect for this purpose.
If this is not your case, please open a regular support ticket and send a simple, fully runnable project that isolates the problem so that I can inspect it locally and provide a more to the point answer.
All the best,
Slav
the Telerik team
The code samples you posted appear to be correct. If you add the user control that contains the RadDocks in code-behind, you must do so in any of the events that take place before LoadDockLayout to ensure that the stored state will be applied correctlu. The Page.Init event is perfect for this purpose.
If this is not your case, please open a regular support ticket and send a simple, fully runnable project that isolates the problem so that I can inspect it locally and provide a more to the point answer.
All the best,
Slav
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
Martin Roussel
Top achievements
Rank 1
answered on 09 Jan 2013, 05:23 PM
Slav, the ticket is now open, including a sample containing the issue.
After more research, ive also noted that if the code is in a normal aspx page and into a RadTabStrip (using PageView ContentUrl), the problem is not there. It seems that it needs to be in a user control in a RadTabStrip.
TIA
Martin
After more research, ive also noted that if the code is in a normal aspx page and into a RadTabStrip (using PageView ContentUrl), the problem is not there. It seems that it needs to be in a user control in a RadTabStrip.
TIA
Martin
0
Hello Martin,
I have provided steps for resolving your problem in the support ticket. As I mentioned previously you need to load the user control with the RadDocks on the Init event of the page to ensure that their state is loaded correctly instead of using the PageViewCreated event of RadMultiPage for this purpose. If you need further assistance, let us continue our discussion on the matter in the support ticket.
All the best,
Slav
the Telerik team
I have provided steps for resolving your problem in the support ticket. As I mentioned previously you need to load the user control with the RadDocks on the Init event of the page to ensure that their state is loaded correctly instead of using the PageViewCreated event of RadMultiPage for this purpose. If you need further assistance, let us continue our discussion on the matter in the support ticket.
All the best,
Slav
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.