private void LoadRootNodes(RadTreeView treeView) { const string sql = "Select Name, ItemID from TNodes where ParentID IS NULL "; SqlConnection dbCon = new SqlConnection("Data Source=localhost;Initial Catalog=Telerik;user id=sa; password=knowdev"); SqlDataAdapter adapter = new SqlDataAdapter(sql, dbCon); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); RadTreeNode node = new RadTreeNode(); foreach (DataRow row in dataTable.Rows) { //RadTreeViewContextMenu contextmenu1 = new RadTreeViewContextMenu(); //contextmenu1.ID = row["Name"].ToString(); //RadTreeView2.ContextMenus.Add(contextmenu1); //contextmenu1.Items.Add(new RadMenuItem(row["Name"].ToString())); node.Text = row["Name"].ToString(); node.Value = row["ItemID"].ToString(); node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; RadTreeView2.Nodes.Add(node); } foreach (RadTreeNode nd in RadTreeView2.GetAllNodes()) { RadTreeViewContextMenu contextmenu2 = new RadTreeViewContextMenu(); contextmenu2.ID = nd.Text; RadTreeView2.ContextMenus.Add(contextmenu2); nd.ContextMenuID = contextmenu2.ID; contextmenu2.Items.Add(new RadMenuItem(nd.Text)); } } //ON Expand protected void RadTreeView2_NodeExpand(object sender, RadTreeNodeEventArgs e) { const string sql = @" SELECT TNodes.ItemID AS NodeId, TNodes.Name AS NodeText, COUNT(Children.ItemID) AS ChildCount FROM TNodes LEFT JOIN TNodes As Children ON TNodes.ItemID = Children.ParentId WHERE TNodes.ParentId = @parentId GROUP BY TNodes.ItemID, TNodes.Name "; SqlConnection dbCon = new SqlConnection("Data Source=localhost;Initial Catalog=Telerik;user id=sa; password=knowdev"); SqlDataAdapter adapter = new SqlDataAdapter(sql, dbCon); adapter.SelectCommand.Parameters.AddWithValue("parentId", e.Node.Value); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); foreach (DataRow row in dataTable.Rows) { RadTreeNode node = new RadTreeNode(); node.Text = row["NodeText"].ToString(); node.Value = row["NodeId"].ToString(); if (Convert.ToInt32(row["ChildCount"]) > 0) { node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; } if (!(e.Node.TreeView.ContextMenus[0].ID == "test")) { e.Node.TreeView.ContextMenus[0].Items[0].Text = "test"; e.Node.TreeView.ContextMenus[0].Items[0].Value = "1"; } e.Node.Nodes.Add(node); } e.Node.Expanded = true; //e.Node.ExpandMode = TreeNodeExpandMode.ClientSide; foreach (RadTreeNode nd in e.Node.GetAllNodes()) { RadTreeViewContextMenu contextmenu = new RadTreeViewContextMenu(); contextmenu.ID = nd.Text; RadTreeView2.ContextMenus.Add(contextmenu); nd.ContextMenuID = contextmenu.ID; contextmenu.Items.Add(new RadMenuItem(nd.Text)); } }Hi,
I am using RadTreeview context menu items. Issue is that after node expand context menu does not show. In above mentioned code on page load
if(!IsPostBack)
LoadRootNodes(RadTreeView2);
LoadRootNodes() functioned is called at that time context menu show properly. but when I expand the node it does not show.
Code is mentioned above. Please suggest.
Thanks,