Telerik RadMenu provides three server-side events - ItemClick, ItemCreated and ItemDataBound.
ItemClick
The server-side ItemClick event is fired after a menu postback. The instance of the clicked item is passed to the ItemClick event handler - you can obtain a reference to it using the RadMenuEventArgs.
| C# |
Copy Code |
|
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) { Telerik.WebControls.RadMenuItem ItemClicked = e.Item; Response.Write("Server event raised -- you clicked: " + ItemClicked.Text); } |
| VB.NET |
Copy Code |
|
Protected Sub RadMenu1_ItemClick(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) Handles RadMenu1.ItemClick Dim ItemClicked As Telerik.WebControls.RadMenuItem = e.Item Response.Write("Server event raised -- you clicked: " + ItemClicked.Text) End Sub |
ItemCreated
ItemCreated is fired every time a new item is added to the RadMenu instance. ItemCreated is not related to Data Binding and you cannot retrieve the DataItem of the item in the ItemCreated event handler. ItemCreated is often useful in scenarios where you want to initialize all items- for example setting the ToolTip of each item to be equal to the Text property.
| C# |
Copy Code |
|
protected void RadMenu1_ItemCreated(object sender, RadMenuEventArgs e) { Response.Write("This item was just added to the menu: " + e.Item.Text + "<br>"); } |
| VB.NET |
Copy Code |
|
Protected Sub RadMenu1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) Handles RadMenu1.ItemCreated Response.Write("This item was just added to the menu: " + e.Item.Text + "<br>") End Sub |
The output will be similar to this:

ItemDataBound
ItamDataBound is fired for each item whenever you are binding the Telerik RadMenu (setting a DataSource and calling DataBind() explicitly or using declarative Data Binding through DataSourceID in ASP.NET 2.0). You can retrieve the item being bound using the RadMenuEventArgs. The DataItem associated with the item can be retrieved with e.DataItem property. You need to cast the DataItem to the type of the datasource item you are binding to and then map fields from the DataItem to their respective properties in the RadMenuItem class.
| C# |
Copy Code |
|
private DataTable CreateTestTable() { DataTable table = new DataTable();
table.Columns.Add("ID"); table.Columns.Add("ParentID"); table.Columns.Add("Text");
table.Rows.Add(new object[] { "1", null, "Root 1" }); table.Rows.Add(new object[] { "2", null, "Root 2" }); table.Rows.Add(new object[] { "a", 1, "Child 1.1" }); table.Rows.Add(new object[] { "aa", 1, "Child 1.2" }); table.Rows.Add(new object[] { "b", "2", "Child 2.1" }); table.Rows.Add(new object[] { "bb", "2", "Child 2.2" });
return table; } protected void Page_Load(object sender, EventArgs e) { RadMenu1.DataSource = CreateTestTable(); RadMenu1.DataFieldID = "ID"; RadMenu1.DataFieldParentID = "ParentID"; RadMenu1.DataBind(); }
protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) { DataRowView row = (DataRowView)e.Item.DataItem; e.Item.Text = row["Text"].ToString(); } |
| VB.NET |
Copy Code |
|
Private Function CreateTestTable() As DataTable Dim table As New DataTable()
table.Columns.Add("ID") table.Columns.Add("ParentID") table.Columns.Add("Text")
table.Rows.Add(New Object() {"1", Nothing, "Root 1"}) table.Rows.Add(New Object() {"2", Nothing, "Root 2"}) table.Rows.Add(New Object() {"a", 1, "Child 1.1"}) table.Rows.Add(New Object() {"aa", 1, "Child 1.2"}) table.Rows.Add(New Object() {"b", "2", "Child 2.1"}) table.Rows.Add(New Object() {"bb", "2", "Child 2.2"})
Return table End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load RadMenu1.DataSource = CreateTestTable() RadMenu1.DataFieldID = "ID" RadMenu1.DataFieldParentID = "ParentID" RadMenu1.DataBind()
End Sub Protected Sub RadMenu1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.RadMenuEventArgs) Handles RadMenu1.ItemDataBound
Dim row As DataRowView = CType(e.Item.DataItem, DataRowView) e.Item.Text = row("Text").ToString() End Sub |
See Also