Hello
In this post : http://www.telerik.com/community/forums/aspnet-ajax/treeview/how-to-handle-node-templates-with-load-on-demand.aspx
i've asked support about how to put togheter load on demand and treeview nodes templates, and the following post has given me hints on how to add gridviews into node templates at runtimes :
http://www.telerik.com/community/forums/aspnet-ajax/treeview/adding-the-radgrid-in-the-nodetemplate-dynamically.aspx.
Now i've got a tree with the following structure :
year 1
|_ first quarter
|_ department (uses load on demand , server side)
|_code (uses load on demand , server side)
|_template Node : contains an asp.net userControl with a radgrid
|_ second quarter ...
year 2 ...
All nodes are added programmatically, and the department and code subnodes load their children on demand. Now i need the template node to contains some richer controls to display more than a string , so i've chosen a radgrid.
The radgrid rows should contain also a link button to allow the user to edit the selected record (not inline but redirecting to an appropriate page ).
I've put the grid into a usercontrol and bound it to an objectdatasource, hoping it avoided me to define all the grid properties programmatically, but i can't achieve it , instead if i set the datasource programmaticaly to one of my businness object (which returns a datatable ) it gets instantiated, but i haven't sorting, paging etc.
the second problem happens when i open any of the load on demand nodes : if i had preaviuosly opened another load on demand node , its template node (the grid) gets resetted to an empty node.
Below i've added the code of the page that uses the custom control with grid and the custom control itsself :
1. load on demand expand method
2. custom control node template html
3. custom control template node code behind:
thank you in advance for your support
In this post : http://www.telerik.com/community/forums/aspnet-ajax/treeview/how-to-handle-node-templates-with-load-on-demand.aspx
i've asked support about how to put togheter load on demand and treeview nodes templates, and the following post has given me hints on how to add gridviews into node templates at runtimes :
http://www.telerik.com/community/forums/aspnet-ajax/treeview/adding-the-radgrid-in-the-nodetemplate-dynamically.aspx.
Now i've got a tree with the following structure :
year 1
|_ first quarter
|_ department (uses load on demand , server side)
|_code (uses load on demand , server side)
|_template Node : contains an asp.net userControl with a radgrid
|_ second quarter ...
year 2 ...
All nodes are added programmatically, and the department and code subnodes load their children on demand. Now i need the template node to contains some richer controls to display more than a string , so i've chosen a radgrid.
The radgrid rows should contain also a link button to allow the user to edit the selected record (not inline but redirecting to an appropriate page ).
I've put the grid into a usercontrol and bound it to an objectdatasource, hoping it avoided me to define all the grid properties programmatically, but i can't achieve it , instead if i set the datasource programmaticaly to one of my businness object (which returns a datatable ) it gets instantiated, but i haven't sorting, paging etc.
the second problem happens when i open any of the load on demand nodes : if i had preaviuosly opened another load on demand node , its template node (the grid) gets resetted to an empty node.
Below i've added the code of the page that uses the custom control with grid and the custom control itsself :
1. load on demand expand method
protected
void
RTVIndagini_NodeExpand(
object
sender, RadTreeNodeEventArgs e)
{
//if (e.Node.Nodes.Count != 0) return;
switch
(e.Node.Category)
{
case
"trimestre"
:
{
decimal
anno =
int
.Parse(e.Node.ParentNode.Value);
decimal
trimestre =
int
.Parse(e.Node.Value);
IndagineModel im =
new
IndagineModel();
IDictionary<
decimal
, String> enti = im.getEnti(anno, trimestre);
foreach
(
decimal
key
in
enti.Keys)
{
RadTreeNode nodoEnte =
new
RadTreeNode(enti[key], key.ToString());
nodoEnte.Category =
"ente"
;
nodoEnte.ExpandMode = TreeNodeExpandMode.ServerSide;
e.Node.Nodes.Add(nodoEnte);
}
break
;
}
case
"ente"
:
{
Decimal ente = Decimal.Parse(e.Node.Value);
RadTreeNode trimestre = e.Node.ParentNode;
Decimal trimestreValue = Decimal.Parse(trimestre.Value);
Decimal anno = Decimal.Parse(trimestre.ParentNode.Value);
IndagineModel im =
new
IndagineModel();
IDictionary<String,String> codiciReclamo = im.getCodiciReclamo(anno, trimestreValue, ente);
foreach
(String key
in
codiciReclamo.Keys )
{
RadTreeNode nodoCodiceReclamo =
new
RadTreeNode(
String.Format(
"{0} - {1}"
, key, codiciReclamo[key]), key);
nodoCodiceReclamo.Category =
"codicereclamo"
;
nodoCodiceReclamo.ExpandMode = TreeNodeExpandMode.ServerSide;
e.Node.Nodes.Add(nodoCodiceReclamo);
}
break
;
}
case
"codicereclamo"
:
{
DatiPratiche dto =
new
DatiPratiche();
dto.reclamo = e.Node.Value;
RadTreeNode ente = e.Node.ParentNode;
dto.ente =
decimal
.Parse(e.Node.ParentNode.Value);
RadTreeNode trimestre = ente.ParentNode;
dto.trimestre =
decimal
.Parse(trimestre.Value);
dto.anno =
decimal
.Parse(trimestre.ParentNode.Value);
//TestNodeTempateOnDemand tst = new TestNodeTempateOnDemand();
customControls_Indagine_NodeTemplate tst =
new
customControls_Indagine_NodeTemplate();
RadTreeNode temp =
new
RadTreeNode();
tst.InstantiateIn(temp);
e.Node.Nodes.Add(temp);
RTVIndagini.DataBind();
}
break
;
}
//e.Node.Expanded = true;
e.Node.ExpandMode = TreeNodeExpandMode.ClientSide;
//RTVIndagini.DataBind();
}
2. custom control node template html
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NodeTemplate.ascx.cs" Inherits="customControls_Indagine_NodeTemplate" %>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"ObjectDataSource1"
GridLines
=
"None"
Skin
=
"Web20"
onitemdatabound
=
"RadGrid1_ItemDataBound"
AllowPaging
=
"True"
AllowSorting
=
"True"
>
<
MasterTableView
DataSourceID
=
"ObjectDataSource1"
AutoGenerateColumns
=
"False"
DataKeyNames
=
"C_COD_REC"
>
<
RowIndicatorColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"C_COD_REC"
HeaderText
=
"C_COD_REC"
ReadOnly
=
"True"
SortExpression
=
"C_COD_REC"
UniqueName
=
"C_COD_REC"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"C_MAC_ARE"
HeaderText
=
"C_MAC_ARE"
SortExpression
=
"C_MAC_ARE"
UniqueName
=
"C_MAC_ARE"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"C_ARE"
HeaderText
=
"C_ARE"
SortExpression
=
"C_ARE"
UniqueName
=
"C_ARE"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"C_DET"
HeaderText
=
"C_DET"
SortExpression
=
"C_DET"
UniqueName
=
"C_DET"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"T_RIF_TAB"
DataType
=
"System.Decimal"
HeaderText
=
"T_RIF_TAB"
SortExpression
=
"T_RIF_TAB"
UniqueName
=
"T_RIF_TAB"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"C_MOD"
HeaderText
=
"C_MOD"
SortExpression
=
"C_MOD"
UniqueName
=
"C_MOD"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:ObjectDataSource
ID
=
"ObjectDataSource1"
runat
=
"server"
DeleteMethod
=
"delete"
InsertMethod
=
"insert"
OldValuesParameterFormatString
=
"original_{0}"
SelectMethod
=
"getDatiCodice"
TypeName
=
"CodiceReclamo"
UpdateMethod
=
"update"
>
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Original_C_COD_REC"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_MAC_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_DET"
Type
=
"String"
/>
</
DeleteParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"T_RIF_TAB"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"Original_C_COD_REC"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_MAC_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"C_MOD"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_C_DET"
Type
=
"String"
/>
</
UpdateParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"C_COD_REC"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"C_MAC_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"C_ARE"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"C_DET"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"T_RIF_TAB"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"C_MOD"
Type
=
"String"
/>
</
InsertParameters
>
</
asp:ObjectDataSource
>
3. custom control template node code behind:
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;
public
partial
class
customControls_Indagine_NodeTemplate : System.Web.UI.UserControl,ITemplate
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
#region ITemplate Members
public
void
InstantiateIn(Control container)
{
RadGrid RadGrid1 =
new
RadGrid();
RadGrid1.DataBinding +=
new
EventHandler(RadGrid_DataBinding);
container.Controls.Add(RadGrid1);
}
void
RadGrid_DataBinding(
object
sender, EventArgs e)
{
// I must add the following line of code to see the grid displayed
//inside the tree node, but i don't have any paging, sorting ...
//RadGrid target = (RadGrid)sender;
//RadTreeNode node = (RadTreeNode)target.BindingContainer;
//EnteModello em = new EnteModello();
//target.DataSource = em.getModelliPerEnte();
}
#endregion
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
}
}
thank you in advance for your support