asp.net中的绑定菜单 [英] binding menu in asp.net
问题描述
大家好,
我从后面的代码中填充了菜单.现在的问题是,我想以不同的方式设置菜单和子菜单的颜色,并且在单击子菜单时我想根据URL来以不同的方式移动到下一页.
我在产品"中有以下字段:
Hi all ,
I populated the menu from code behind .Now the problem is this I want to set color of menu and sub-menus differently and on click of sub-menu I want to move on next page differently as per URL.
I have fields in Products as:
ProductID,CategoryID,ProductName, URl
请帮忙
Please help
private void PopulateMenu()
{
DataSet ds = GetDataSetForMenu();
Menu menu = new Menu();
foreach (DataRow parentItem in ds.Tables["Categories"].Rows)
{
MenuItem categoryItem = new MenuItem((string)parentItem["CategoryName"]);
menu.Items.Add(categoryItem);
foreach (DataRow childItem in parentItem.GetChildRows("Children"))
{
MenuItem childrenItem = new MenuItem((string)childItem["ProductName"]);
categoryItem.ChildItems.Add(childrenItem);
}
}
Panel1.Controls.Add(menu);
Panel1.DataBind();
}
private DataSet GetDataSetForMenu()
{
SqlDataAdapter adCat = new SqlDataAdapter("SELECT * FROM Categories", con);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT * FROM Products", con);
DataSet ds = new DataSet();
adCat.Fill(ds, "Categories");
adProd.Fill(ds, "Products");
ds.Relations.Add("Children",
ds.Tables["Categories"].Columns["CategoryID"],
ds.Tables["Products"].Columns["CategoryID"]);
return ds;
}
并希望将其方向更改为水平.
请帮帮我.
在此先感谢.
and want to shift its orientation as horizontal.
Please help me.
Thanks in Advance.
推荐答案
我要设置颜色菜单和子菜单不同
I want to set color of menu and sub-menus differently
使用CSS
通过菜单控件使用CSS和样式 [ ^ ]
菜单类 [ ^ ]
Use CSS
Using CSS and Styles with the Menu Control[^]
Menu Class[^]
在单击子菜单时,我想根据URL以不同的方式移动到下一页.
on click of sub-menu I want to move on next page differently as per URL.
有属性NavigateUrl
可以为导航分配URL.
MenuItem.NavigateUrl属性 [为asp中的菜单项动态设置NavigateUrl.净c# [
There is property NavigateUrl
to assign the URL for the navigation.
MenuItem.NavigateUrl Property[^]
Dynamically set NavigateUrl for a menu item in asp.net c#[^]
这篇关于asp.net中的绑定菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!