ok.create a recursive method which get data from database and select the main menu with appropriate condition. now, check the sub menu with your linked main menu key/main menu link that sub menu exist or not. If the sub menu exist then call the method again and same condition for sub menu.
You add those value with your appropriate css and html in a string value.
like this example:
string _menu= "<ul><li><a href=""+menu_link_from_db+"" target="_blank">"+menu_name_from_db+"</a></li></ul>";
so if you complete debug your recursive method then your result string will increase like following string.
start your code, try yourself. if any problem face then knock us.
Thank you.
Rashed::Bangladesh.