This is a migrated thread and some comments may be shown as answers.

unable to fire RadTreeView_NodeDataBound

10 Answers 121 Views
Dock
This is a migrated thread and some comments may be shown as answers.
anand
Top achievements
Rank 1
anand asked on 23 Dec 2008, 11:29 AM
hi,

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

Sort by
0
Yana
Telerik team
answered on 23 Dec 2008, 02:16 PM
Hello,

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.
0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 03:03 PM
hi,

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>', '&nbsp;&nbsp;&nbsp;', 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>','&nbsp;&nbsp;&nbsp;', 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();

 

 

 

}

0
Atanas Korchev
Telerik team
answered on 23 Dec 2008, 03:06 PM
Hello anand,

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.
0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 03:30 PM
hi,

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
0
Atanas Korchev
Telerik team
answered on 23 Dec 2008, 03:37 PM
Hello anand,

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.
0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 03:48 PM
hi,

Thanks it works.

Thanks & regards
anand gole
0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 03:50 PM
hi,

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
0
Atanas Korchev
Telerik team
answered on 23 Dec 2008, 03:52 PM
Hi anand,

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.
0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 04:02 PM
hi,

 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.

0
anand
Top achievements
Rank 1
answered on 23 Dec 2008, 04:41 PM
this problem is resolved.

thanks for  your support

Thanks & regards
Anand Gole
Tags
Dock
Asked by
anand
Top achievements
Rank 1
Answers by
Yana
Telerik team
anand
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or