tblPages
[Column Name], [Data Type], [Allow Nulls]
PageID, int, false -- (an identity field)
PageParentID, int, true
PageTitle, varchar(50), true
PageContent, text, true
In an ASCX, I have the following,
<telerik:RadMenu ID="NavMenu" runat="server" DataSourceID="NavigationSqlDataSource" Width="100%" DataFieldID="PageID" DataFieldParentID="PageParentID" DataTextField="PageTitle"> |
<CollapseAnimation Duration="200" Type="OutQuint" /> |
</telerik:RadMenu> |
<asp:SqlDataSource |
ID="NavigationSqlDataSource" |
runat="server" |
ConnectionString="[OMITTED]" |
SelectCommand="SELECT * FROM [tblPages]"> |
</asp:SqlDataSource> |
I don't have any problems with the menu displaying, however, what I'm unclear about, is how to take the "PageID" from the database above and simply have the RadMenu take a click and go to something like:
~/page.aspx?id=[PAGEID]
Where [PAGEID], would of course, be an integer that could be looked up (if necissary, using my own code), which would allow me to display the content.
I just want a click on the menu to go to something like "~/page.aspx?id=[PAGEID]". Is there an event or something where I can set this to happen? Is there something built into the control (realize, I'm using the Q1 2008 version)?
Thanks for any assistance or help or even ideas you can supply.
6 Answers, 1 is accepted

Here is my code:
protected void NavMenu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) |
{ |
DataRowView dataRow = (DataRowView)e.Item.DataItem; |
// doesn't work: "Object reference not set to an instance of an object" |
Int32 PageID = Convert.ToInt32(dataRow["PageID"]); |
// and this won't work, due to the above |
e.Item.NavigateUrl = ResolveUrl( String.Format( "~/page.aspx?id={0}", PageID ) ); |
} |
As previously mentioned, the menu renders just fine using the SQL server table I explained above. It's the clicks that I want to direct.
I suppose if I can't get a response, then I'll end up having to pull the data out of SQL server and manually/dynamically build the entire menu control in a page load ... which I really hate to do, since there has to be an easier way. Some help, please.

protected void NavMenu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e) |
{ |
// won't work, end up with 0 instead of the PageID value |
Int32 PageID = Convert.ToInt32( e.Item.Attributes["PageID"] ); |
// which causes this to fail |
e.Item.NavigateUrl = ResolveUrl( String.Format("~/page.aspx?id={0}", PageID) ); |
} |
Normally I don't design mode bind to database tables, but since it is built in ... trying to figure out how. The menu renders perfectly ... except (repeating myself) I need to dynamically link menu items to a page ... which should be pretty apparent from my above code example. I expect I'm being stupid and am missing something extremely simple. Can anyone please help?
You can try the following:
protected void NavMenu_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
int pageId = (int)DataBinder.Eval(e.Item.DataItem, "PageID");
e.Item.NavigateUrl = ResolveUrl( String.Format("~/page.aspx?id={0}", PageID) );
}
This should be the event handler of the ItemDataBound event of RadMenu. Also make sure you are not using the ItemClick event. ItemClick does not work when NavigateUrl of the item is set.
If for some reason you need to handle ItemClick you can use a different approach:
- Bind Value property to the PageID field by setting the DataValueField property of RadMenu to "PageID"
- During the ItemClick event handler use the Value property of the clicked item to obtain the associated PageID and then do Response.Redirect
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

protected void NavMenu_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e) |
{ |
Int32 PageID = Convert.ToInt32( DataBinder.Eval(e.Item.DataItem, "PageID") ); |
e.Item.NavigateUrl = ResolveUrl( String.Format("~/page.aspx?id={0}", PageID) ); |
} |

Hi.
I use a radmenu & bind it to a table as fallow
TblPages
pg_ID int
pg_ParentID int (alow null)
pg_Title nvarchar(100)
it's my radmenu:
<telerik:RadMenu ID="RadMenu1" runat="server" DataFieldID="pg_ID" DataFieldParentID="pg_ParentID"
DataSourceID="sds_Menu" DataTextField="pg_Title" EnableRoundedCorners="True"
EnableShadows="True" Flow="Vertical" OnItemClick="RadMenu1_ItemClick" OnItemDataBound="RadMenu1_ItemDataBound"
Skin="Windows7" Width="180px" Style="top: 0px; right: 0px"
DataValueField="pg_ID">
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadMenu>
<asp:SqlDataSource ID="sds_Menu" runat="server" ConnectionString="<%$ ConnectionStrings:AerobicConnectionString %>"
SelectCommand="SELECT pg_ID, pg_ParentID, pg_Title, pg_Value, pg_Order FROM Pages ORDER BY pg_Order">
</asp:SqlDataSource>
and it is codebehind:
protected void RadMenu1_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
int pageId = (int)DataBinder.Eval(e.Item.DataItem, "pg_ID");
e.Item.NavigateUrl = ResolveUrl(String.Format("~/page.aspx?id={0}", pageId));
}
protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
DataRowView dataRow = (DataRowView)e.Item.DataItem;
Int32 PageID = Convert.ToInt32(dataRow["pg_ID"]);
e.Item.NavigateUrl = ResolveUrl(String.Format("~/page.aspx?id={0}", PageID));
}
it work property.
Now,I want to do this:when click a menu whitout opening a new window show Content of that page in current page.
could u help me?
sorry for my bad writing
Thanks alot.

I am having some difficulty understanding your requirement. Are you trying to set the "target" property of the "NavigateUrl" property of the RadMenuItem to "Same Window"? It does not look like this is possible with the RadMenuItem API.
There is a "Target=" property for a RadMenuItem that can be set at design time. Would this help?
<
telerik:RadMenuItem
runat
=
"server"
Height
=
"50px"
ImageUrl
=
"~/images/help_button.jpg"
Target
=
"_self"
NavigateUrl
=
"http://www.telerik.com"
Width
=
"150px"
>
</
telerik:RadMenuItem
>
Would you consider using a RadPageView or RadWindow embedded in the page as an alternative?
Please clarify.