dynamic menu...
-
Hi to all, I am working on a shopping cart project. Here the scenerio is, if the admin adds a new category, that should be shown in the menu. If the admin adds a new sub category , then it should be displayed as the child item of the main category. Can anybody suggest me how to achieve this. cheers sneha
cheers, sneha
-
Hi to all, I am working on a shopping cart project. Here the scenerio is, if the admin adds a new category, that should be shown in the menu. If the admin adds a new sub category , then it should be displayed as the child item of the main category. Can anybody suggest me how to achieve this. cheers sneha
cheers, sneha
A dynamic menu will be done using javascript. Just look at any of the menus that exist on the web and work out how to make one work using dynamic properties instead of a static file, or even just write that file as needed.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
A dynamic menu will be done using javascript. Just look at any of the menus that exist on the web and work out how to make one work using dynamic properties instead of a static file, or even just write that file as needed.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Thank you for replying. I did like this:
using System;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class _Default : System.Web.UI.Page
{
string name;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
populate_menu();
}
}DataSet GetMenuData() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings\["newcon"\].ConnectionString); SqlCommand cmd = new SqlCommand(); ArrayList arl = new ArrayList(); cmd.Connection = con; cmd.CommandText = "select \* from CATEGORY "; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); cmd.Connection.Open(); sda.Fill(ds, "CATEGORY"); return ds; } public void populate\_menu() { DataSet ds = GetMenuData(); foreach(DataRow drow in ds.Tables\["CATEGORY"\].Rows) { MenuItem masteritem = new MenuItem((string)drow\["category\_name"\]); name = masteritem.Text; get\_id(); int par\_id = Convert.ToInt32 (ViewState\["p\_id"\]); if (par\_id == 0) { Menu1.Items.Add(masteritem); } else { //masteritem.ChildItems.Add(masteritem); Menu1.Items.Add(masteritem); } } } public void get\_id() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings\["newcon"\].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select parent\_id from CATEGORY where category\_name='"+name+"'"; cmd.Connection.Open(); int pa\_id = Convert.ToInt32(cmd.ExecuteScalar()); ViewState\["p\_id"\] = pa\_id; }
}
From this I am getting output like this: Catering Plastics Glassware
cheers, sneha
-
Thank you for replying. I did like this:
using System;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class _Default : System.Web.UI.Page
{
string name;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
populate_menu();
}
}DataSet GetMenuData() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings\["newcon"\].ConnectionString); SqlCommand cmd = new SqlCommand(); ArrayList arl = new ArrayList(); cmd.Connection = con; cmd.CommandText = "select \* from CATEGORY "; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); cmd.Connection.Open(); sda.Fill(ds, "CATEGORY"); return ds; } public void populate\_menu() { DataSet ds = GetMenuData(); foreach(DataRow drow in ds.Tables\["CATEGORY"\].Rows) { MenuItem masteritem = new MenuItem((string)drow\["category\_name"\]); name = masteritem.Text; get\_id(); int par\_id = Convert.ToInt32 (ViewState\["p\_id"\]); if (par\_id == 0) { Menu1.Items.Add(masteritem); } else { //masteritem.ChildItems.Add(masteritem); Menu1.Items.Add(masteritem); } } } public void get\_id() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings\["newcon"\].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "select parent\_id from CATEGORY where category\_name='"+name+"'"; cmd.Connection.Open(); int pa\_id = Convert.ToInt32(cmd.ExecuteScalar()); ViewState\["p\_id"\] = pa\_id; }
}
From this I am getting output like this: Catering Plastics Glassware
cheers, sneha
Looks about right. You're not adding subitems, you're adding all your items to the one menu
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Looks about right. You're not adding subitems, you're adding all your items to the one menu
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Hi,
public void populate\_menu() { DataSet ds = GetMenuData(); foreach(DataRow drow in ds.Tables\["CATEGORY"\].Rows) { MenuItem masteritem = new MenuItem((string)drow\["category\_name"\]); name = masteritem.Text; get\_id(); par\_id = Convert.ToInt32 (ViewState\["p\_id"\]); if (par\_id == 0) { Menu1.Items.Add(masteritem); } else { //now find the category whose category\_id is par\_id get\_category\_name(); ca\_name = ViewState\["cname"\].ToString(); //then under that category, add this sub category Menu1.Items**\[0\]**.ChildItems.Add(masteritem); } } }
In this I am unable to find the menu index of a particular category. In this I just tried by giving it as "0". I want the menuindex based on the category name "ca_name".
cheers, sneha