I am building a treeview with a grid like template (it may also become a
listview rather than a grid). When I load the non-templated nodes via
.aspx it works fine, when I try do build the tree dynamically on server
side it fails with the following error:
The DataSourceID of 'ctl00' must be the ID of a control of type IDataSource. A control with ID 'Level 0' could not be found
I am not sure what I am doing wrong, any assistance would be appreciated.
I have attached a picture of what the correct display.
Working code:
Not Working Code:
The DataSourceID of 'ctl00' must be the ID of a control of type IDataSource. A control with ID 'Level 0' could not be found
I am not sure what I am doing wrong, any assistance would be appreciated.
I have attached a picture of what the correct display.
Working code:
<%@ Page Language="C#" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<script runat="server"> |
protected override void OnInit(EventArgs e) |
{ |
RadTreeView1.NodeTemplate = new RadGridTemplate(); |
base.OnInit(e); |
} |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
foreach (RadTreeNode node1 in RadTreeView1.GetAllNodes()) |
{ |
if (node1.Level == 1) |
node1.Nodes.Add(new RadTreeNode("SqlDataSource1")); |
} |
} |
RadTreeView1.DataBind(); |
} |
class RadGridTemplate : ITemplate |
{ |
public void InstantiateIn(Control container) |
{ |
RadGrid RadGrid1 = new RadGrid(); |
RadGrid1.DataBinding += new EventHandler(RadGrid_DataBinding); |
container.Controls.Add(RadGrid1); |
} |
private void RadGrid_DataBinding(object sender, EventArgs e) |
{ |
RadGrid target = (RadGrid)sender; |
RadTreeNode node = (RadTreeNode)target.BindingContainer; |
string source = (string)DataBinder.Eval(node, "Text"); |
target.DataSourceID = source; |
} |
} |
</script> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> |
<telerik:RadTreeView ID="RadTreeView1" Runat="server"> |
<Nodes> |
<telerik:RadTreeNode Text="Level 0"> |
<Nodes> |
<telerik:RadTreeNode Text="Level 1a" /> |
<telerik:RadTreeNode Text="Level 1b" /> |
<telerik:RadTreeNode Text="Level 1c" /> |
<telerik:RadTreeNode Text="Level 1d" /> |
<telerik:RadTreeNode Text="Level 1e" /> |
<telerik:RadTreeNode Text="Level 1f" /> |
</Nodes> |
</telerik:RadTreeNode> |
</Nodes> |
</telerik:RadTreeView> |
</form> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GolfLeague %>" |
SelectCommand="select * from scores where memberid = 1" |
SelectCommandType="Text"> |
</asp:SqlDataSource> |
</body> |
</html> |
Not Working Code:
<%@ Page Language="C#" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<script runat="server"> |
protected override void OnInit(EventArgs e) |
{ |
RadTreeView1.NodeTemplate = new RadGridTemplate(); |
base.OnInit(e); |
} |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
LoadTree(); |
foreach (RadTreeNode node1 in RadTreeView1.GetAllNodes()) |
{ |
if (node1.Level == 1) |
node1.Nodes.Add(new RadTreeNode("SqlDataSource1")); |
} |
} |
RadTreeView1.DataBind(); |
} |
protected void LoadTree() |
{ |
// |
// ORIGINAL HIERACHICAL LOADING OF TREEVIEW |
// |
// get the hierachical data from the DAL |
//DataTable dt = DAL.Routines.getFlightPlayerTree(); |
//treeView.DataTextField = "Name"; |
//treeView.DataFieldID = "ID"; |
//treeView.DataValueField = "ID"; |
//treeView.DataFieldParentID = "ParentID"; |
//treeView.DataSource = dt; |
RadTreeView1.Nodes.Clear(); |
RadTreeNode node = new RadTreeNode("Level 0"); |
node.Nodes.Add(new RadTreeNode("Level 1a")); |
node.Nodes.Add(new RadTreeNode("Level 1b")); |
node.Nodes.Add(new RadTreeNode("Level 1c")); |
node.Nodes.Add(new RadTreeNode("Level 1d")); |
node.Nodes.Add(new RadTreeNode("Level 1e")); |
node.Nodes.Add(new RadTreeNode("Level 1f")); |
RadTreeView1.Nodes.Add(node); |
} |
class RadGridTemplate : ITemplate |
{ |
public void InstantiateIn(Control container) |
{ |
RadGrid RadGrid1 = new RadGrid(); |
RadGrid1.DataBinding += new EventHandler(RadGrid_DataBinding); |
container.Controls.Add(RadGrid1); |
} |
private void RadGrid_DataBinding(object sender, EventArgs e) |
{ |
RadGrid target = (RadGrid)sender; |
RadTreeNode node = (RadTreeNode)target.BindingContainer; |
string source = (string)DataBinder.Eval(node, "Text"); |
target.DataSourceID = source; |
} |
} |
</script> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> |
<telerik:RadTreeView ID="RadTreeView1" Runat="server"> |
</telerik:RadTreeView> |
</form> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GolfLeague %>" |
SelectCommand="select * from scores where memberid = 1" |
SelectCommandType="Text"> |
</asp:SqlDataSource> |
</body> |
</html> |