Hi Telerik,
I am using radmenu control in my website which has 3 items namely podium,office and the forum as the top navigation items.all the top navigation items have subitems with different font,color,background image.
I want to change the rmSlide class for each top navigation item.So that Podium uses rmSlide,The Office uses rmSlide1 and The forum to uses rmSlide2.
all the 3 dropdown has diffrent bg example podium(pink),office(blue) and the forum(brown).
So Please help me to solve this issue.
ACCX
ASCX.cs
I am using radmenu control in my website which has 3 items namely podium,office and the forum as the top navigation items.all the top navigation items have subitems with different font,color,background image.
I want to change the rmSlide class for each top navigation item.So that Podium uses rmSlide,The Office uses rmSlide1 and The forum to uses rmSlide2.
all the 3 dropdown has diffrent bg example podium(pink),office(blue) and the forum(brown).
So Please help me to solve this issue.
ACCX
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="QatarRadMenuBar.ascx.cs" Inherits="UserControls_QatarRadMenuBar" %><%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %><asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" StartFromCurrentNode="false" StartingNodeOffset="1" /><telerik:RadMenu runat="server" ID="menuTopNavigation"> <DefaultGroupSettings RepeatColumns="2" RepeatDirection="Horizontal" Height="259px" Width="159px" /> </telerik:RadMenu>ASCX.cs
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using Telerik.Web.UI;using Telerik.Cms.Web;using System.Threading;public partial class UserControls_QatarRadMenuBar : System.Web.UI.UserControl{ private string strLiStartMain = "<li class='firstLevel'>"; private string strLiStartFirst = "<li class='secondLevel'>"; private string strLiStartMainSelected = "<li class='firstLevelSelected'>"; private string strLiStartFirstSelected = "<li class='secondLevelSelected'>"; private string strLiStartMain1 = "<li class='firstLevel1'>"; private string strLiStartFirst1 = "<li class='secondLevel1'>"; private string strLiStartMainSelected1 = "<li class='firstLevelSelected1'>"; private string strLiStartFirstSelected1 = "<li class='secondLevelSelected1'>"; private string strEndLi = "</li>"; private string strEndUl = "</ul>"; private string strLiNextLevelSelected = string.Empty; private string strLiStartSecond = string.Empty; private string strUlStartMain = string.Empty; private string strUlStartSecond = string.Empty; private string strUlStartMainRight = string.Empty; private string strUlStartSecondRight = string.Empty; private string strLiNextLevelSelected1 = string.Empty; private string strLiStartSecond1 = string.Empty; private string strUlStartMain1 = string.Empty; private string strUlStartSecond1 = string.Empty; private string strUlStartMainRight1 = string.Empty; private string strUlStartSecondRight1 = string.Empty; protected void Page_Load(object sender, EventArgs e) { BuildQPMenu(); } private void BuildQPMenu() { if (Resources.GlobalResource.Direction.ToUpper() == "RTL") { strLiNextLevelSelected = "<li style='padding-right:{0}px;background-position:{1}px center;' class='nextLevelSelected'>"; strLiStartSecond = "<li style='padding-right:{0}px;background-position:{1}px center;' class='nextLevel'>"; strUlStartMain = "<ul style='list-style: none; margin: 0;padding: 0 8px 0 30px;' class='levelBorder'>"; strUlStartSecond = "<ul style='list-style: none; margin: 0;padding: 8px 10px 0 30px;' class='levelBorder'>"; strUlStartMainRight = "<ul style='list-style: none; margin: 0;padding: 0 8px 0 30px;'>"; strUlStartSecondRight = "<ul style='list-style: none; margin: 0;padding: 8px 10px 0 30px;'>"; } else { strLiNextLevelSelected = "<li style='padding-left:{0}px;background-position:{1}px center;' class='nextLevelSelected'>"; strLiStartSecond = "<li style='padding-left:{0}px;background-position:{1}px center;' class='nextLevel'>"; strUlStartMain = "<ul style='list-style: none; margin: 0;padding: 0 30px 0 6px;' class='levelBorder'>"; strUlStartSecond = "<ul style='list-style: none; margin: 0;padding: 0px 30px 0 6px;' class='levelBorder'>"; strUlStartMainRight = "<ul style='list-style: none; margin: 0;padding: 0 30px 0 6px;' class='levelBorder'>"; strUlStartSecondRight = "<ul style='list-style: none; margin: 0;padding: 0px 30px 0 6px;' >"; strLiNextLevelSelected1 = "<li style='padding-left:{0}px;background-position:{1}px center;' class='nextLevelSelected1'>"; strLiStartSecond1 = "<li style='padding-left:{0}px;background-position:{1}px center;' class='nextLevel1'>"; strUlStartMain1 = "<ul style='list-style: none; margin: 0;padding: 0 30px 0 6px;' class='levelBorder1'>"; strUlStartSecond1 = "<ul style='list-style: none; margin: 0;padding: 0px 30px 0 6px;' class='levelBorder1'>"; strUlStartMainRight1 = "<ul style='list-style: none; margin: 0;padding: 0 30px 0 6px;' class='levelBorder1'>"; strUlStartSecondRight1 = "<ul style='list-style: none; margin: 0;padding: 0px 30px 0 6px;' >"; } menuTopNavigation.Items.Clear(); SiteMapNodeCollection topNodecollection = SiteMapDataSource1.Provider.GetChildNodes(SiteMapDataSource1.Provider.RootNode); if (topNodecollection.Count > 0) { string numbers = ""; foreach (SiteMapNode toplevel in topNodecollection[0].ChildNodes)//topNodecollection[0] is [SiteMap] { RadMenuItem itemtoplevel = new RadMenuItem(toplevel.Title.ToUpper(), this.ResolveUrl(toplevel.Url)); if (toplevel.Url.Contains("Podium")) { itemtoplevel.GroupSettings.RepeatColumns = 4; itemtoplevel.Text= "<span style='font-size:10px;'>THE</span> Podium"; numbers = ""; } else if (toplevel.Url.Contains("Office")) { itemtoplevel.GroupSettings.RepeatColumns = 5; itemtoplevel.Text = "<span style='font-size:10px;'>THE</span> Office"; numbers = "1"; } else if (toplevel.Url.Contains("Forum")) { itemtoplevel.GroupSettings.RepeatColumns = 1; itemtoplevel.Text = "<span style='font-size:10px;'>THE</span> Forum"; numbers = "2"; } menuTopNavigation.Items.Add(itemtoplevel); if (HttpContext.Current.Request.FilePath.ToUpper().Contains(itemtoplevel.NavigateUrl.ToUpper().Replace(".ASPX", ""))) { itemtoplevel.CssClass = "RadTopLevelItemSelected"; } if (toplevel.HasChildNodes) { int secondlevelcount = 0; foreach (SiteMapNode secondlevel in toplevel.ChildNodes) { if (UserHasPermission(secondlevel)) { RadMenuItem itemsecondlevel = new RadMenuItem(); //itemsecondlevel.Width = Unit.Pixel(222); LiteralControl liUlStart = null; if (secondlevelcount < menuTopNavigation.DefaultGroupSettings.RepeatColumns)// only for first items for RepeatColumns add top padding { if (secondlevelcount == 0 || (secondlevelcount % 2 == 0)) { if (toplevel.ChildNodes.Count >= menuTopNavigation.DefaultGroupSettings.RepeatColumns) { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartMain1); } else { liUlStart = GetLiteralControl(strUlStartMain); } } else { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartMainRight1); } else { liUlStart = GetLiteralControl(strUlStartMainRight); } } } else { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartMainRight1); } else { liUlStart = GetLiteralControl(strUlStartMainRight); } } } else { if (secondlevelcount == 0 || (secondlevelcount % 2 == 0)) { if (toplevel.ChildNodes.Count >= menuTopNavigation.DefaultGroupSettings.RepeatColumns) { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartSecond1); } else { liUlStart = GetLiteralControl(strUlStartSecond); } } else { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartMainRight1); } else { liUlStart = GetLiteralControl(strUlStartMainRight); } } } else { if (numbers == "1") { liUlStart = GetLiteralControl(strUlStartSecondRight1); } else { liUlStart = GetLiteralControl(strUlStartSecondRight); } } } itemsecondlevel.Controls.Add(liUlStart); if (HttpContext.Current.Request.FilePath.ToUpper().Contains(this.ResolveUrl(secondlevel.Url).ToUpper().Replace(".ASPX", ""))) { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartMainSelected1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartMainSelected)); } } else { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartMain1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartMain)); } } itemsecondlevel.Controls.Add(GetNavigatingHyperlink(secondlevel.Key, secondlevel.Title, secondlevel.Url)); itemsecondlevel.Controls.Add(GetLiteralControl(strEndLi)); if (secondlevel.HasChildNodes) { foreach (SiteMapNode thirdlevel in secondlevel.ChildNodes) { if (UserHasPermission(thirdlevel)) { if (HttpContext.Current.Request.FilePath.ToUpper().Contains(this.ResolveUrl(thirdlevel.Url).ToUpper().Replace(".ASPX", ""))) { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirstSelected1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirstSelected)); } } else if (thirdlevel.HasChildNodes) { if (HttpContext.Current.Request.FilePath.ToUpper().Contains(this.ResolveUrl(thirdlevel.Url.Substring(0, thirdlevel.Url.LastIndexOf("/"))).ToUpper().Replace(".ASPX", ""))) { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirstSelected1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirstSelected)); } } else { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirst1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirst)); } } } else { if (numbers == "1") { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirst1)); } else { itemsecondlevel.Controls.Add(GetLiteralControl(strLiStartFirst)); } } itemsecondlevel.Controls.Add(GetNavigatingHyperlink(thirdlevel.Key, thirdlevel.Title, thirdlevel.Url)); itemsecondlevel.Controls.Add(GetLiteralControl(strEndLi)); if (thirdlevel.HasChildNodes) { AddNextLevels(ref itemsecondlevel, thirdlevel, 0,numbers); } } } } itemsecondlevel.Controls.Add(GetLiteralControl(strEndUl)); itemtoplevel.Items.Add(itemsecondlevel); secondlevelcount++; } } } } } } private bool UserHasPermission(SiteMapNode node) { return node.IsAccessibleToUser(HttpContext.Current); } private void AddNextLevels(ref RadMenuItem itemsecondlevel, SiteMapNode nextLevelNode, int count,string numbers) { LiteralControl liStart = null; foreach (SiteMapNode currentNode in nextLevelNode.ChildNodes) { if (UserHasPermission(currentNode)) { if (Resources.GlobalResource.Direction.ToUpper() == "RTL") { if (HttpContext.Current.Request.FilePath.ToUpper().Contains(this.ResolveUrl(currentNode.Url).ToUpper().Replace(".ASPX", ""))) { if (numbers == "1") { liStart = GetLiteralControl(string.Format(strLiNextLevelSelected1, 40 + (10 * count), 144 - (10 * count))); } else { liStart = GetLiteralControl(string.Format(strLiNextLevelSelected, 40 + (10 * count), 144 - (10 * count))); } } else { if (numbers == "1") { liStart = GetLiteralControl(string.Format(strLiStartSecond1, 40 + (10 * count), 144 - (10 * count))); } else { liStart = GetLiteralControl(string.Format(strLiStartSecond, 40 + (10 * count), 144 - (10 * count))); } } } else { if (HttpContext.Current.Request.FilePath.ToUpper().Contains(this.ResolveUrl(currentNode.Url).ToUpper().Replace(".ASPX", ""))) { if (numbers == "1") { liStart = GetLiteralControl(string.Format(strLiNextLevelSelected1, 30 + (10 * count), 22 + (10 * count))); } else { liStart = GetLiteralControl(string.Format(strLiNextLevelSelected, 30 + (10 * count), 22 + (10 * count))); } } else { if (numbers == "1") { liStart = GetLiteralControl(string.Format(strLiStartSecond1, 30 + (10 * count), 22 + (10 * count))); } else { liStart = GetLiteralControl(string.Format(strLiStartSecond, 30 + (10 * count), 22 + (10 * count))); } } } itemsecondlevel.Controls.Add(liStart); itemsecondlevel.Controls.Add(GetNavigatingHyperlink(currentNode.Key, currentNode.Title, currentNode.Url)); itemsecondlevel.Controls.Add(GetLiteralControl(strEndLi)); if (currentNode.HasChildNodes) { count++; AddNextLevels(ref itemsecondlevel, currentNode, count,numbers); } } } } private LiteralControl GetLiteralControl(string text) { return new LiteralControl(text); } private HyperLink GetNavigatingHyperlink(string key, string text, string navigatingUrl) { HyperLink hlNavigator = new HyperLink(); hlNavigator.ID = key; hlNavigator.NavigateUrl = navigatingUrl; hlNavigator.Text = text; return hlNavigator; }}