I have a RadGrid and I want to use one of the column to dynamically add new RadDock but nothing happened. I created a single asp:Button to test my FederationDetailBtnClick method which add dock correctly but the button from grid failed. Help needed!!!
aspx file:
aspx.cs file:
aspx file:
<
telerik:RadGrid
ID
=
"FederationGrid"
runat
=
"server"
OnNeedDataSource
=
"FederationGrid_NeedDataSource"
OnItemCreated
=
"FederationGrid_ItemCreated"
OnItemDataBound
=
"FederationGrid_ItemDataBound"
>
<
MasterTableView
EnableHierarchyExpandAll
=
"true"
AutoGenerateColumns
=
"False"
TableLayout
=
"Fixed"
DataKeyNames
=
"Id"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Id"
HeaderText
=
"Federation Name"
UniqueName
=
"FederationId"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Status"
HeaderText
=
"Status"
UniqueName
=
"Status"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
HeaderText
=
"Federation Detail"
Text
=
"Detail"
UniqueName
=
"FederationDetail"
ButtonType
=
"PushButton"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel"
runat
=
"server"
LoadingPanelID
=
"RadAjaxLoadingPanel"
>
<
telerik:RadDockLayout
runat
=
"server"
ID
=
"RadDockLayout_Federation"
OnSaveDockLayout
=
"RadDockLayout_SaveDockLayout"
OnLoadDockLayout
=
"RadDockLayout_LoadDockLayout"
>
<
telerik:RadDockZone
ID
=
"RadDockZone_Federation"
runat
=
"server"
Orientation
=
"Horizontal"
>
</
telerik:RadDockZone
>
</
telerik:RadDockLayout
>
</
telerik:RadAjaxPanel
>
aspx.cs file:
private
List<DockState> CurrentDockStates
{
get
{
// Store the info about the added docks in the session.
List<DockState> _currentDockStates = (List<DockState>)Session[
"CurrentDockStatesDeployment"
];
if
(Object.Equals(_currentDockStates,
null
))
{
_currentDockStates =
new
List<DockState>();
Session[
"CurrentDockStatesDeployment"
] = _currentDockStates;
}
return
_currentDockStates;
}
set
{
Session[
"CurrentDockStatesDeployment"
] = value;
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
FederationGrid_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
this
.federationList = DataModelRequestHandler.GetFederationsAsync(
this
.environment);
FederationGrid.DataSource =
this
.federationList;
}
protected
void
FederationGrid_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dataitem = (GridDataItem)e.Item;
Button btn = (Button)dataitem[
"FederationDetail"
].Controls[0];
btn.Click +=
new
EventHandler(FederationDetailBtnClick);
}
}
protected
void
FederationGrid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dataitem = (GridDataItem)e.Item;
Button btn = (Button)dataitem[
"FederationDetail"
].Controls[0];
btn.CommandArgument = (e.Item
as
GridDataItem)[
"FederationId"
].Text;
}
}
protected
void
RadDockLayout_LoadDockLayout(
object
sender, DockLayoutEventArgs e)
{
// Populate the event args with the state information. The RadDockLayout control
// will automatically move the docks according that information.
foreach
(DockState state
in
CurrentDockStates)
{
e.Positions[state.UniqueName] = state.DockZoneID;
e.Indices[state.UniqueName] = state.Index;
}
}
protected
void
RadDockLayout_SaveDockLayout(
object
sender, DockLayoutEventArgs e)
{
CurrentDockStates = RadDockLayout_Federation.GetRegisteredDocksState();
}
private
void
FederationDetailBtnClick(
object
sender, EventArgs e)
{
var btnView = (Button)sender;
var FederationId = btnView.CommandArgument;
// Create RadDock
RadDock dock =
this
.CreateRadDock(FederationId);
// Dock it on DockZone
RadDockLayout_Federation.Controls.Add(dock);
dock.Dock(RadDockZone_Federation);
}
private
RadDock CreateRadDock(
string
dockTitle)
{
RadDock dock =
new
RadDock();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace(
"-"
,
"a"
);
dock.ID =
string
.Format(
"RadDock{0}"
, dock.UniqueName);
dock.Title = dockTitle;
dock.Commands.Add(
new
DockCloseCommand());
dock.Commands.Add(
new
DockExpandCollapseCommand());
return
dock;
}