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

NavigateURL - Format the URL String

8 Answers 204 Views
Menu
This is a migrated thread and some comments may be shown as answers.
sayitfast
Top achievements
Rank 2
sayitfast asked on 07 May 2009, 05:23 AM
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

 

8 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 07 May 2009, 07:37 AM
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.
0
sayitfast
Top achievements
Rank 2
answered on 07 May 2009, 08:28 AM
Thank you so much!  Exactly what I needed.


Thanks again...
0
Qball
Top achievements
Rank 1
answered on 01 Dec 2009, 05:33 PM

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

0
Veselin Vasilev
Telerik team
answered on 02 Dec 2009, 10:35 AM
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.
0
Qball
Top achievements
Rank 1
answered on 02 Dec 2009, 07:36 PM

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

0
Casey
Top achievements
Rank 1
answered on 02 Dec 2009, 08:16 PM

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
0
Qball
Top achievements
Rank 1
answered on 02 Dec 2009, 08:43 PM

Thanks Casey

That was it, all works great now.

 

Thank you both for all your help.

 

0
Ronnie
Top achievements
Rank 1
answered on 09 Apr 2010, 03:46 PM

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

Tags
Menu
Asked by
sayitfast
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
sayitfast
Top achievements
Rank 2
Qball
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Casey
Top achievements
Rank 1
Ronnie
Top achievements
Rank 1
Share this question
or