Showing posts with label menus. Show all posts
Showing posts with label menus. Show all posts

Thursday, September 24, 2015

asp.net create menu from datatable

public static string CrateMenuFromDT(DataTable dt)
        {
            string retstring = "";


            DataRow[] drparentMain = dt.Select("ParentID =0 OR ParentID is null");

            foreach (DataRow dr in drparentMain)
            {
                string strmenuselect = Convert.ToString(dr["selected"]) == "0" ? "menu_nonselected" : "menu_selected";
                string strsubmenu = "";


                DataRow[] drparentMenu = dt.Select("ParentID =" + Convert.ToString(dr["MenuID"]));
                foreach (DataRow pdr in drparentMenu)
                {
                    if (strsubmenu == "")
                        strsubmenu = " <div class='submenu_straight'><ul><li><a href='" + Convert.ToString(pdr["navigateurl"]) + "' class='parent'><p>" + Convert.ToString(pdr["Text"]) + "</p></a></li>";
                    else
                        strsubmenu = strsubmenu + "<li><a href='" + Convert.ToString(pdr["navigateurl"]) + "' class='parent'><p>" + Convert.ToString(pdr["Text"]) + "</p></a></li>";
                }

                if (strsubmenu != "")
                    strsubmenu = strsubmenu + "</ul></div>";


                if (retstring == "")
                    retstring = "<li class='" + strmenuselect + "'><p><a href='" + Convert.ToString(dr["navigateurl"]) + "'>" + Convert.ToString(dr["Text"]) + "</a></p>" + strsubmenu + "</li>";
                else
                    retstring = retstring + "<li class='" + strmenuselect + "'><p><a href='" + Convert.ToString(dr["navigateurl"]) + "'>" + Convert.ToString(dr["Text"]) + "</a></p>" + strsubmenu + "</li>";

            }

            return retstring;
        }