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

[Solved] Setting width for menu items

8 Answers 220 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chaiyouth Tiemchaipum
Top achievements
Rank 1
Chaiyouth Tiemchaipum asked on 18 Feb 2010, 10:12 AM
Hi all,

I'm implementing menus binding with data from sitemap. I would like to know how can I set width for menu items since those data
are rendered on the fly not the static one.

Many thanks,
Oat

8 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 18 Feb 2010, 11:54 AM
Hello Chaiyouth Tiemchaipum,

To achieve your goal you should use one of the BindTo(...) overloads, which provides the ability to set properties for each item. Here is a code snippet which shows how to accomplish this task:
<%= Html.Telerik().Menu()
       .Name("Menu")
       .BindTo("sample", (i,n)=> i.HtmlAttributes = new{width = "100px"})
%>

Regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chaiyouth Tiemchaipum
Top achievements
Rank 1
answered on 19 Feb 2010, 04:24 AM
Hello Georgi,

Thanks for your response. However, I still got a runtime error with your code snippet saying
    CS1593: Delegate 'System.Action<Telerik.Web.Mvc.UI.NavigationBindingFactory<Telerik.Web.Mvc.UI.MenuItem>>' does not take 2 arguments

Am I missing something? I'm using VS2010 RC with ASP.NET MVC2 RC2 for this code.

Best Regards,
Oat
0
Georgi Krustev
Telerik team
answered on 19 Feb 2010, 09:39 AM
Hi Chaiyouth,

For your convenience I have created a test project implementing the required functionality. The project is attached to this message. Please note that the solution is for VS2008, but there should be no problem to run it on VS2010.

Kind regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Chaiyouth Tiemchaipum
Top achievements
Rank 1
answered on 24 Feb 2010, 10:10 AM
Thanks Georgi !
0
Toby Riley
Top achievements
Rank 1
answered on 12 Jul 2010, 03:20 PM
Hi,

I have tried this and although it added the width attribute to the HTML nothing changes?!
Help....
0
Georgi Krustev
Telerik team
answered on 12 Jul 2010, 04:17 PM
Hello Tobias,

Did you check test project attached to my last message? Could you check what differences you noticed?

If the problem still persists I will ask you to post the code of the View in order to proceed with the investigation of the problem.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alaa Masoud
Top achievements
Rank 1
answered on 05 Mar 2011, 03:38 PM
I downloaded the project, however converted mvc assemblies to mvc ver 3
The menu items width does not change!

I also tried this:

@{Html.Telerik().Menu().Name("AdminMenu").Items(menu=> {
    menu.Add()
      .Text("Menu1").Url("~/admin/menu1/")
      .HtmlAttributes(new { width="100px" })
      .Items(items => {
        items.Add().Text("Something").Url("~/admin/menu1/something");
      });
    menu.Add()
      .Text("This is menu 2").Url("~/admin/menu2")
      .HtmlAttributes(new { width="100px" });
    menu.Add()
      .Text("3").Url("~/admin/menu3")
      .HtmlAttributes(new { width = "100px" });
  }).Render();
  }

What I want is to have the same width for all top level menu items but the width attribute seem to do nothing. What am I missing?

Thanks!
0
Kritika
Top achievements
Rank 1
answered on 28 Oct 2011, 10:55 AM
Hi,
you should try syntax like this:

@(Html.Telerik().Menu()
.Name("Menu")
.Items(menu =>
{
menu.Add().Text("Example1").Action("Index", "Home" }).HtmlAttributes(new { style = "width:210px;" });
menu.Add().Text("Example2").Action("Index", "Home" }).HtmlAttributes(new { style = "width:210px;" });
menu.Add().Text("Example3").Action("Index", "Home" }).HtmlAttributes(new { style = "width:210px;" });
})
)

I have tried this and is working perfectly.
Tags
Menu
Asked by
Chaiyouth Tiemchaipum
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Chaiyouth Tiemchaipum
Top achievements
Rank 1
Toby Riley
Top achievements
Rank 1
Alaa Masoud
Top achievements
Rank 1
Kritika
Top achievements
Rank 1
Share this question
or