NavigateURL - Format the URL String

9 posts, 1 answers
  1. sayitfast
    sayitfast avatar
    57 posts
    Member since:
    Oct 2006

    Posted 07 May 2009 Link to this post

    I have a RadMenu bound to a linq datasource... the datasource contains a URL field that is supplied when a person creates a new db record or page.

    I then wanted to use a query string in the menu for the url....  I was wanting to do something like this but it will not work.

     

    <telerik:RadMenu ID="RadMenu1" Runat="server" DataFieldID="MapID"

     

     

    DataFieldParentID="ParentID" DataNavigateUrlField='<%# Eval("Url", "?Url={0}") %>'

     

     

    DataSourceID="LinqDataSource1" DataTextField="Title"

     

     

    Skin="Telerik" Width="100%" >

    basicly I just want the menu to postback to the default.aspx page where I have a details view.

    somehing like this" default.aspx?Url=PageName

    Any ideas?

    Thanks

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2009 Link to this post

    Hello,

    The DataNavigateUrlField helps identify the column from the database which contains the url of the items. So rather than using this property you can try setting the NavigateUrl for items in the ItemDataBound event of your RadMenu:
    c#:
    protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) 
        { 
            e.Item.NavigateUrl = "~/Default.aspx?Url=" + DataBinder.Eval(e.Item.DataItem, "PageName"); 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. sayitfast
    sayitfast avatar
    57 posts
    Member since:
    Oct 2006

    Posted 07 May 2009 Link to this post

    Thank you so much!  Exactly what I needed.


    Thanks again...
  5. Qball
    Qball avatar
    8 posts
    Member since:
    Dec 2009

    Posted 01 Dec 2009 Link to this post

    Hi

    I have a similar problem; I am attempting to set the DataNavigationalUrlField like this:

    DataNavigateUrlField="~/Default.aspx?Menuid={0}"

    Unfortunately the url just shows this when clicked Default.aspx# 

    I have also tried this:

    protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)

    {

    e.Item.NavigateUrl = "~/Default.aspx?Menuid={0}";

    }

    Hope someone can help

  6. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 02 Dec 2009 Link to this post

    Hello Qball,

    The DataNavigationalUrlField points to a column in your datasource which contains the URL.
    You need to use the ItemDataBound event in your case:

    protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)
    {
      DataRowView row = (DataRowView)e.Item.DataItem;
      e.Item.NavigateUrl = "~/Default.aspx?Menuid=" + row["menuID"].ToString();
    }



    All the best,
    Veselin Vasilev
    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.
  7. Qball
    Qball avatar
    8 posts
    Member since:
    Dec 2009

    Posted 02 Dec 2009 Link to this post

    Hi Thank you for the quick response.

     

    Unfortunately this still hasn't corrected the problem.  When I hover or click over the links the page just refreshes e.g Default.aspx#
    I have pasted my code in below.

     

    <

    radM:RadMenu ID="RadMenu1" DataTextField="Text" runat="server" DataSourceID="SqlDataSource1" DataFieldID="MenuID" DataFieldParentID="ParentID" DefaultGroupSettings-ExpandDirection=Right SkinsPath="~/RadControls/Menu/Skins" Flow="Vertical" Skin="CssGrey" DataNavigateUrlField="RadMenu1_ItemDataBound">

     

    </

    radM:RadMenu>

    code behind

     

    public

    partial class WHGC : System.Web.UI.MasterPage

     

     

     

    {

     

    protected void Page_Load(object sender, EventArgs e)

     

    {

    }

     

    protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)

     

    {

     

    DataRowView row = (DataRowView)e.Item.DataItem;

     

    e.Item.NavigateUrl =

    "~/Default.aspx?Menuid=" + row["menuID"].ToString();

     

    }

    }



    Hope you can help.
    Many Thanks

  8. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 02 Dec 2009 Link to this post

    Hi Qball,

    I believe Veselin was suggesting that you use the code in the ItemDataBound event of the RadMenu: 

    OnItemDataBound="RadMenu1_ItemDataBound" 

    It looks like you put this instead:
    DataNavigateUrlField="RadMenu1_ItemDataBound" 

    Hope this helps,
    Casey
  9. Qball
    Qball avatar
    8 posts
    Member since:
    Dec 2009

    Posted 02 Dec 2009 Link to this post

    Thanks Casey

    That was it, all works great now.

     

    Thank you both for all your help.

     

  10. Ronnie
    Ronnie avatar
    29 posts
    Member since:
    Oct 2008

    Posted 09 Apr 2010 Link to this post

    Hello,

    Thank you Princy.  Likewise this is what I was looking for.

    I just have an issue that is raised which I'm not sure it can be resolved.
    Currently I don't have a ParentID field in my db table and I'm about to add it so that I can include the DataFieldParentID capability.
    Also, since I'm using the ID for the DataNavigationUrlField there will always be a value.

       protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)  
       {  
          e.Item.NavigateUrl = "~/Page.aspx?Id=" + DataBinder.Eval(e.Item.DataItem, "ID");  
       } 

    Problem I'm encountering is that if the items (ParentID) intent is to only be a text field without any navigation, the url is created anyways.

    My thoughts are that the only thing I can do is add a UrlField (char(5)) in my db table and 'duplicate add  or leave empty' the ID value to it and use it as the DataNavigationUrlField.

    Before I make the necessary db changes, any alternative thoughts or ideas are appreciated.

    Thank you in advance,
    Ronnie

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017