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

Need to convert asp menu to radmenu code behind

0 Answers 90 Views
Menu
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 28 Feb 2009, 02:25 PM
Hi, I have an asp.net application and wish to convert the asp menu to a rad menu and need some help with the code behind.  Here is the current asp menu code behind.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Vevo;
using Vevo.DataAccessCache;
using Vevo.DataAccessLib;

public partial class Components_CategoryNavMenuList : Vevo.Language.BaseLanguageUserControl
{
    private int _nodeDepth = 0;
    private int _maxNode = 0;
    
    private string CategoryID
    {
        get
        {
            string id = Request.QueryString["CategoryID"];
            if (String.IsNullOrEmpty( id ))
                return "0";
            else
                return id;
        }
    }


    private string CategoryName
    {
        get
        {
            if (Request.QueryString["CategoryName"] == null)
                return String.Empty;
            else
                return Request.QueryString["CategoryName"];
        }
    }

    private void PopulateControls()
    {
        DataTable table = CategoryAccessCache.Instance.GetByParentID(
            CultureUtilities.StoreCultureID, "0", "SortOrder", FlagFilter.ShowTrue );

        uxCategoryNavListMenu.Items.Clear();
        foreach (DataRow row in table.Rows)
        {
            uxCategoryNavListMenu.Items.Add( NewItem( row ) );
            _nodeDepth = 0;
        }

        foreach (MenuItem mi in uxCategoryNavListMenu.Items)
        {
            CategoryItem( mi, CategoryID, CategoryName );
        }
    }

    private void CategoryItem( MenuItem menuItem, string categoryID, string categoryName )
    {
        if (menuItem.Value == categoryID || menuItem.Text == categoryName)
        {
            if (menuItem.Value == CategoryID || menuItem.Text == CategoryName)
                menuItem.Selected = true;
            //if (menuItem.Parent != null)
            //    menuItem.Parent.Selected = true;
            return;
        }
        else
        {
            foreach (MenuItem mi in menuItem.ChildItems)
            {
                if (mi.Value == categoryID || mi.Text == categoryName)
                {
                    if (mi.Value == CategoryID || mi.Text == CategoryName)
                        mi.Selected = true;
                    CategoryItem( menuItem, mi.Parent.Value, mi.Parent.Text );
                    return;
                }
                CategoryItem( mi, categoryID, categoryName );
            }
        }
    }

    private void PopulateCategories( MenuItem item, string parentCategoryID )
    {
        DataTable table = CategoryAccessCache.Instance.GetByParentID( CultureUtilities.StoreCultureID, parentCategoryID, "SortOrder", FlagFilter.ShowTrue );

        foreach (DataRow row in table.Rows)
        {
            item.ChildItems.Add( NewItem( row ) );
        }
    }

    private MenuItem NewItem( DataRow row )
    {
        MenuItem newItem = new MenuItem();
        newItem.Text = row["Name"].ToString();
        newItem.Value = row["CategoryID"].ToString();

        if (CategoryAccessCache.Instance.IsCategoryIDNotLeaf( row["CategoryID"].ToString() ))
        {
            newItem.NavigateUrl = UrlManager.GetCategoryUrl( row["CategoryID"].ToString(), row["UrlName"].ToString() );

            _nodeDepth++;
            if (_nodeDepth < MaxNode) //Max Tree depth
                PopulateCategories( newItem, row["CategoryID"].ToString() );
            _nodeDepth--;
        }
        else
        {
            newItem.NavigateUrl = UrlManager.GetCategoryUrl( row["CategoryID"].ToString(), row["UrlName"].ToString() );
        }
        return newItem;
    }


    protected void Page_Load( object sender, EventArgs e )
    {
        if (!IsPostBack)
        {
            PopulateControls();
        }
    }

    
    public int MaxNode
    {
        get
        {
            return _maxNode;
        }
        set
        {
            _maxNode = value;
        }
    }

    public void Refresh()
    {
        PopulateControls();
    }
}

No answers yet. Maybe you can help?

Tags
Menu
Asked by
chris
Top achievements
Rank 1
Share this question
or