Css
<div>
<ul id="nav" runat="server"></ul>
</div>
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
using System.Configuration;
public partial class home : System.Web.UI.Page
{
Code objcode = new Code();
protected void Page_Load(object sender, EventArgs e)
{
menu();
}
public void menu()
{
string content = string.Empty;
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["datacon"].ConnectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from menu", con);
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
string st="#";
content += "<li><a href='" + st + "'>" + dr["menu_name"] + "</a>" + submenu(dr["menu_name"].ToString()) + "</li>";
}
nav.InnerHtml = content;
}
}
public string submenu(string str)
{
string content = string.Empty;
content += "<ul>";
if (str.Trim() == "About Us")
{
content += bindmainmenu();
}
if (str.Trim() == "Contact Us")
{
content += bindmainmenu2();
}
content += "</ul>";
return content;
}
public string bindmainmenu()
{
string content = string.Empty;
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["datacon"].ConnectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from sub_menu", con);
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
content += "<li><a href='" + dr["menu_url"] + "?pid=" + dr["id"] + "'" + ">" + dr["menu_name"] + "</a></li>";
}
}
return content;
}
public string bindmainmenu2()
{
string content = string.Empty;
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["datacon"].ConnectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from sub_menu2", con);
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
content += "<li><a href='" + dr["menu_url"] + "?pid=" + dr["id"] + "'" + ">" + dr["menu_name"] + "</a></li>";
}
}
return content;
}
}
No comments:
Post a Comment