Hi i have a table which i was using with a datagrid using hyperlink to maintain a simple menu to browse a internal site. but now i decided to create a horizontal menu with the Menu Component of asp.net, i know there is a different way how to do this, using sitemap for example. but i really want to keep my table providing all the path.

My table have the following columns

Which Option_Fun identify the parent for example
1, Google, www.google.com, General
2, Yahoo, www.yahoo.com, General

so in that case i know that under General i have 2 links. well my thing is can i generate a menu using as datasource my table?

Thanks any other suggestion i will appreciate.

Do you mean?


yes something like that. i have not try it yet, but I am wonder how im going to set the sub menus and all that.


If you have submenus as well i dont think its possible to do what you want and use datasource(but im not sure).
Why not build your self the routine, that take out the table from the DB and populate the menu "manually".

You're saying populate the menu manually thru a sitemap?

Yea a sitemap or build a usercontrol that has subitems, or use others control that has item --> subitems...,
Its up to you to decide which control \ method to use.

Ok, thanks for your help, I will be playing around with some of it. I let you know how i am doing.


Yea not a problem, if you need any help on the control you have decided to work with, do not be shy to ask.

Dont forget to close this therad, by flag it as solved.

i think what you need is a self-referencing table, so the records will have two fields one of which is primary key and the other one is foreign key to its parent. by doing that you can have limitless hierarchy of links.

I found what i wanted.

protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
        private void PopulateMenu()
            DataSet ds = GetDataSetForMenu();
            foreach (DataRow parentItem in ds.Tables["MENUOPTS_T"].Rows)
                MenuItem categoryItem = new MenuItem((string)parentItem["OPTION_FNCTN"]);
                foreach (DataRow childItem in parentItem.GetChildRows("Children"))
                    MenuItem childrenItem = new MenuItem((string)childItem["OPTION_DESC"]);
                    childrenItem.NavigateUrl = ((string)childItem["OPTION_LINK"]);
        private DataSet GetDataSetForMenu()
            SqlConnection myConnection = new SqlConnection("Initial Catalog=;Data Source=;UID=;PWD=;");
            SqlDataAdapter adCat = new SqlDataAdapter("SELECT DISTINCT OPTION_FNCTN FROM MENUOPTS_T", myConnection);
            SqlDataAdapter adProd = new SqlDataAdapter("SELECT * FROM EW_V_MENU", myConnection);

            DataSet ds = new DataSet();
            adCat.Fill(ds, "MENUOPTS_T");
            adProd.Fill(ds, "EW_V_MENU");
            dg.DataSource = ds;
            return ds;

Thanks all.