in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

ASPxMenu - BuildMenu example. How can i change this code from C# to VB

Last post 11/14/2008 7:40 AM by Roman R (Developer Express). 3 replies.
Page 1 of 1 (4 items)
Sort Posts:
Previous Next
  • 11/13/2008 4:57 AM

    ASPxMenu - BuildMenu example. How can i change this code from C# to VB

    This is the behind code from the "BuildMenu" example for data binding for ASPxMenu:

    public partial class _Default : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            BuildMenu(ASPxMenu1, AccessDataSource1, false);
        }

        protected void BuildMenu(ASPxMenu menu, SqlDataSource dataSource, bool enableRoles) {
            // Get DataView
            DataSourceSelectArguments arg = new DataSourceSelectArguments();
            DataView dataView = dataSource.Select(arg) as DataView;
            dataView.Sort = "ParentID";

            // Build Menu Items
            Dictionary<string, DevExpress.Web.ASPxMenu.MenuItem> menuItems =
                new Dictionary<string, DevExpress.Web.ASPxMenu.MenuItem>();

            for (int i = 0; i < dataView.Count; i++) {
                DataRow row = dataViewIdea.Row;

                if (!enableRoles || IsAccessible(row)) {
                    DevExpress.Web.ASPxMenu.MenuItem item = CreateMenuItem(row);
                    string itemID = row["ID"].ToString();
                    string parentID = row["ParentID"].ToString();

                    if (menuItems.ContainsKey(parentID))
                        menuItems[parentID].Items.Add(item);
                    else {
                        if (parentID == "0") // It's Root Item
                            menu.Items.Add(item);
                    }
                    menuItems.Add(itemID, item);
                }
            }
        }

        private DevExpress.Web.ASPxMenu.MenuItem CreateMenuItem(DataRow row) {
            DevExpress.Web.ASPxMenu.MenuItem ret = new DevExpress.Web.ASPxMenu.MenuItem();
            ret.Text = row["Text"].ToString();
            ret.NavigateUrl = row["NavigateUrl"].ToString();
            ret.Image.Url = row["ImageUrl"].ToString();
            return ret;
        }

        // Security
        private bool IsAccessible(DataRow row) {
            string[ roles = GetRoles(row["Roles"].ToString());
            return IsInRole(roles);
        }
        private bool IsInRole(string[ roles) {
            foreach (string role in roles) {
                if ((role == "*") || ((HttpContext.Current.User != null) && HttpContext.Current.User.IsInRole(role)))
                    return true;
            }
            return false;
        }

        private string[ GetRoles(string rolesString) {
            List<string> ret = new List<string>();
            foreach (string roleString in rolesString.Split(' ')) {
                string curRoleStr = roleString.Trim();
                if (curRoleStr.Length > 0)
                    ret.Add(curRoleStr);
            }
            return ret.ToArray();
        }

    }

    I want to "translate" this C# to VB

    Thank you a lot.

  • 11/13/2008 2:41 PM In reply to

    Re: ASPxMenu - BuildMenu example. How can i change this code from C# to VB

  • 11/14/2008 4:09 AM In reply to

    Re: ASPxMenu - BuildMenu example. How can i change this code from C# to VB

    Thank you a lot Harry for the answer!

    This tool is fantastic!

    I have an extra question for ASPxMenu,

    Is it possible not to determine a background color for the menu but when the menu and the submenu displays , i can still see the backgroud image of the body of my page?

    I am trying to do that with the "Backcolor" value, but nothing works nice.

    Smile

  • 11/14/2008 7:40 AM In reply to

    Re: ASPxMenu - BuildMenu example. How can i change this code from C# to VB

    Hello

    I believe that you need to set the BackColor property to the Transparent value.

    Thanks, Roman
    R&D, .Net Team
    Developer Express Inc.

    PS. If you wish to receive direct assistance from our Support Team, use
    Support Center at http://www.devexpress.com/Support/Center
Page 1 of 1 (4 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED