Using RadMenu with SQL Database

7 posts, 1 answers
  1. lantram
    lantram avatar
    22 posts
    Member since:
    May 2006

    Posted 05 Nov 2009 Link to this post

    Hello, I'm a customer of and am using "RadControls for ASPNET AJAX Q1 2008", specifically the RadMenu control, and am attempting to bind it to a Microsoft SQL database table. I have the following table defined (simplified):

    [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,

      <CollapseAnimation Duration="200" Type="OutQuint" /> 
      SelectCommand="SELECT * FROM [tblPages]">  

    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:


    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.
  2. lantram
    lantram avatar
    22 posts
    Member since:
    May 2006

    Posted 06 Nov 2009 Link to this post

    Okay, no response from Telerik or anyone else yet, and perhaps I'm really dense in regards to data binding... but since the control does not have the NavigateUrl format whatever thing (which I assume would resolve this entire issue), I'm attempting to do it like this ...

    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.
  3. lantram
    lantram avatar
    22 posts
    Member since:
    May 2006

    Posted 06 Nov 2009 Link to this post

    Still no response, but trying this doesn't work either ...

    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?
  4. Answer
    Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 06 Nov 2009 Link to this post

    Hi Larry Antram,

    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:

    1. Bind Value property to the PageID field by setting the DataValueField property of RadMenu to "PageID"
    2. During the ItemClick event handler use the Value property of the clicked item to obtain the associated PageID and then do Response.Redirect
    the Telerik team

    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.
  5. lantram
    lantram avatar
    22 posts
    Member since:
    May 2006

    Posted 06 Nov 2009 Link to this post

    Thank you! I'm sorry for being such a bonehead, your suggestion works just fine, exactly what I was looking for. Very much appreciated.

    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) );  
  6. razi
    razi avatar
    1 posts
    Member since:
    Jul 2011

    Posted 04 Jan 2012 Link to this post

    I use a radmenu & bind it to a table as fallow

    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"


     <CollapseAnimation Duration="200" Type="OutQuint" />



    <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">


     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.

  7. Richard
    Richard avatar
    479 posts
    Member since:
    Nov 2011

    Posted 04 Jan 2012 Link to this post


    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="" Width="150px" >

    Would you consider using a RadPageView or RadWindow embedded in the page as an alternative?

    Please clarify.
Back to Top