I am using telerik treeview control (asp.net). my requirement is add the context menu at run time. At each node i context menu items are different depending on database field. For that i am using nodedatabound event. but that event is not firing, how to make it enable that.
wating for replay.
anand gole
10 Answers, 1 is accepted
You should call RadTreeView1.DataBind() method in order to fire OnNodeDataBound event.
Greetings,
Yana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

It is not working
please see the code bellow
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadProducts();
}
}
public
void loadProducts()
{
clsDAL oclsDal = new clsDAL();
MySqlDataAdapter oMySqlDataAdapter = new MySqlDataAdapter();
DataSet data;
string getproducts = "select fldProductid, fldproductname from productmaster where deleteflag !=1";
data = oclsDal.getDataset(getproducts);
RadTreeViewContextMenu contextMenu = new RadTreeViewContextMenu();
foreach (DataRow row in data.Tables[0].Rows)
{
RadTreeNode node = new RadTreeNode();
node.Text = row["fldproductname"].ToString();
node.Value = row["fldProductid"].ToString();
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
RadTreeView2.Nodes.Add(node);
RadTreeView2.DataBind();
}
RadTreeView2.CheckBoxes = true;
}
protected void RadTreeView2_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
clsDAL oclsDal = new clsDAL();
string getSections = "";
if (e.Node.ParentNode != null)
{
getSections =
@"select categorymaster.CategoryId,concat('<b>', categorymaster.Name,'</b>', ' ', date_format(Lastupdated,'%d-%m-%Y') ) as Name, activeflag from categorymaster
inner join productsection on productsection.fldSectionId=categorymaster.CategoryId
where CategoryIdRef="
+
e.Node.Value;
}
else
{
getSections =
@"select categorymaster.CategoryId, concat('<b>', categorymaster.Name,'</b>',' ', date_format(Lastupdated,'%d-%m-%Y') ) as Name, activeflag from categorymaster
inner join productsection on productsection.fldSectionId=categorymaster.CategoryId
where CategoryIdRef=0 and productsection.fldProductId="
+
e.Node.Value;
}
DataTable data = oclsDal.getDataTable(getSections);
RadTreeViewContextMenu contextMenu = new RadTreeViewContextMenu();
foreach (DataRow row in data.Rows)
{
RadTreeNode node = new RadTreeNode();
node = new RadTreeNode();
node.Text = row["name"].ToString();
node.Value = row["CategoryId"].ToString();
if (data.Rows.Count > 0)
{
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
}
if (row["activeflag"].ToString() == "2")
{
e.Node.ContextMenuID = "cmEnable";
}
else
{
e.Node.ContextMenuID = "cmDisable";
}
e.Node.Nodes.Add(node);
}
foreach (RadTreeNode node in RadTreeView2.GetAllNodes())
{
node.ContextMenuID = node.Level >= 1 ? "cmEnable" : "cmDisable";
if (node.Level == 0)
{
node.ContextMenuID = "";
}
}
e.Node.Expanded = true;
//e.Node.DataBind();
}
This code does not implement databinding and as a result the NodeDataBound event of RadTreeView will not fire.
To databind radtreeview you need to either set its DataSource property and call the DataBind method or use declarative DataSources and set the DataSourceID property of RadTreeView.
Regards,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

i need to do this because i need to load nodes on demand, beacuse i am having lot of data., my real problem is i want to show context menu, which contains different menus for each node. Menus depends on database field.
Right now i am adding context menu, run time but it showing same menu to all nodes. I don`t want to show menus to root node it should show only chield nodes.
and one mode thing i enabled checkboxes, but i want to show the checkboxes to only cheld nodes not to root nodes,
in you demo link there is no any such type of example so, please give me guidence.
Thanks in advance
anand gole
To disable context menu for certain nodes you should set the EnableContextMenu property for that node to false.
To disable the checkbox for particular node set its Checkable property to false.
Regards,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thanks it works.
Thanks & regards
anand gole

it works thanks
but still that menu problem is there, i am unable to show different menus to different nodes.
how to do that?
thanks and regards
anand gole
Please check this help topic.
Sincerely yours,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

i did same thing please see the code
foreach (DataRow row in data.Rows)
{
RadTreeNode node = new RadTreeNode();
node = new RadTreeNode();
node.Text = row["name"].ToString();
node.Value = row["CategoryId"].ToString();
if (data.Rows.Count > 0)
{
node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
}
if (row["activeflag"].ToString() == "2")
{
e.Node.ContextMenuID = "cmEnable";
}
else
{
e.Node.ContextMenuID = "cmDisable";
}
e.Node.Nodes.Add(node);
}
my html code
<
telerik:radtreeview id="RadTreeView2" runat="server" oncontextmenuitemclick="RadTreeView2_ContextMenuItemClick"
onnodeclick="RadTreeView2_NodeClick" onnodeexpand="RadTreeView2_NodeExpand">
<collapseanimation duration="50" type="OutQuint">
</collapseanimation>
<expandanimation duration="50">
</expandanimation>
<ContextMenus>
<telerik:RadTreeViewContextMenu runat="server" ID="cmDisable" ClickToOpen="True"
Skin="Outlook">
<Items>
<%--<telerik:RadMenuItem Text="Add" Value="Add">
</telerik:RadMenuItem>--
%>
<telerik:RadMenuItem Text="Enjern" Value="Delete">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Deaktivere" Value="Disable">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Endre" Value="Edit">
</telerik:RadMenuItem>
</Items>
<
CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:RadTreeViewContextMenu>
<telerik:RadTreeViewContextMenu runat="server" ID="cmEnable" ClickToOpen="True"
Skin="Outlook">
<Items>
<%--<telerik:RadMenuItem Text="Add" Value="Add">
</telerik:RadMenuItem>--
%>
<telerik:RadMenuItem Text="Enjern" Value="Delete">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Aktivere" Value="Enable">
</telerik:RadMenuItem>
<telerik:RadMenuItem Text="Endre" Value="Edit">
</telerik:RadMenuItem>
</Items>
<
CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:RadTreeViewContextMenu>
</ContextMenus>
</telerik:radtreeview>
it shows first context menu only not second, when i added that context menu to particular node.

thanks for your support
Thanks & regards
Anand Gole