menu控件的使用
来源:互联网 发布:温州软件开发培训班 编辑:程序博客网 时间:2024/05/19 16:19
在.net的导航控件中,我用的最多的是TreeView控件,今天无意间用到了menu控件,感觉挺好的.写出来当作笔记吧!
前台代码:
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
ForeColor="#990000" Height="187px" Orientation="Horizontal" StaticSubMenuIndent="10px"
Style="font-size: 8pt; font-family: Verdana; display: block; background-position-x: center; background-attachment: scroll; background-image: url(img/Alter.jpg); visibility: visible; color: #ff3399; background-repeat: repeat-x; position: static; background-color: #99ff00; text-align: center;" Font-Names="Verdana" Font-Size="0.8em" Width="594px" OnMenuItemClick="Menu1_MenuItemClick">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuStyle BackColor="#FFFBD6" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" />
<StaticSelectedStyle BackColor="#FFCC66" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle BackColor="#B5C7DE" Font-Names="Verdana" Font-Size="8pt" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="5px" VerticalPadding="2px" />
</asp:Menu>
后台代码:
#region 页面初始化
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PR.BLL.menu.A_Menu bll = new PR.BLL.menu.A_Menu();
DataSet ds = bll.GetList();
CreateMenu(1, (MenuItem)null, ds);
}
}
#endregion
#region 递归生成横向菜单
public void CreateMenu(int ParentID, MenuItem tempItem, DataSet ds)
{
DataView dvMenu = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前菜单的所有子节点
dvMenu.RowFilter = "[MenuParentId] = " + ParentID;
foreach (DataRowView Row in dvMenu)
{
if (tempItem == null)
{ //添加根节点
MenuItem Node = new MenuItem();
//节点的文本
Node.Text = Row["FMenuName"].ToString();
//节点旁边的图片
// Node.ImageUrl = "img/" + Row["MenuImage"].ToString();
//有子菜单时的图片
//Node.PopOutImageUrl = "img/02.gif";
this.Menu1.Items.Add(Node);
CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds);//再次递归
}
else
{ //添加当前节点的子节点
MenuItem Node = new MenuItem();
Node.Text = Row["FMenuName"].ToString();
//点击节点后的连接地址
Node.NavigateUrl = Row["Url"].ToString();
//Node.ImageUrl = "Image/" + Row["MenuImage"].ToString();
//Node.Target = Row["left"].ToString();
tempItem.ChildItems.Add(Node);
CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds); //再次递归
}
}
}
#endregion
前台代码:
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
ForeColor="#990000" Height="187px" Orientation="Horizontal" StaticSubMenuIndent="10px"
Style="font-size: 8pt; font-family: Verdana; display: block; background-position-x: center; background-attachment: scroll; background-image: url(img/Alter.jpg); visibility: visible; color: #ff3399; background-repeat: repeat-x; position: static; background-color: #99ff00; text-align: center;" Font-Names="Verdana" Font-Size="0.8em" Width="594px" OnMenuItemClick="Menu1_MenuItemClick">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuStyle BackColor="#FFFBD6" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" />
<StaticSelectedStyle BackColor="#FFCC66" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuItemStyle BackColor="#B5C7DE" Font-Names="Verdana" Font-Size="8pt" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" HorizontalPadding="5px" VerticalPadding="2px" />
</asp:Menu>
后台代码:
#region 页面初始化
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PR.BLL.menu.A_Menu bll = new PR.BLL.menu.A_Menu();
DataSet ds = bll.GetList();
CreateMenu(1, (MenuItem)null, ds);
}
}
#endregion
#region 递归生成横向菜单
public void CreateMenu(int ParentID, MenuItem tempItem, DataSet ds)
{
DataView dvMenu = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前菜单的所有子节点
dvMenu.RowFilter = "[MenuParentId] = " + ParentID;
foreach (DataRowView Row in dvMenu)
{
if (tempItem == null)
{ //添加根节点
MenuItem Node = new MenuItem();
//节点的文本
Node.Text = Row["FMenuName"].ToString();
//节点旁边的图片
// Node.ImageUrl = "img/" + Row["MenuImage"].ToString();
//有子菜单时的图片
//Node.PopOutImageUrl = "img/02.gif";
this.Menu1.Items.Add(Node);
CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds);//再次递归
}
else
{ //添加当前节点的子节点
MenuItem Node = new MenuItem();
Node.Text = Row["FMenuName"].ToString();
//点击节点后的连接地址
Node.NavigateUrl = Row["Url"].ToString();
//Node.ImageUrl = "Image/" + Row["MenuImage"].ToString();
//Node.Target = Row["left"].ToString();
tempItem.ChildItems.Add(Node);
CreateMenu(Int32.Parse(Row["Fid"].ToString()), Node, ds); //再次递归
}
}
}
#endregion
- menu控件的使用
- Menu控件的使用
- menu控件的使用
- Menu控件的使用
- Android 菜单(Menu)控件的使用
- asp.net中menu控件的使用
- 安卓 Menu控件的使用
- 如何使用Menu控件
- android menu控件使用
- 013 menu控件使用
- Menu控件的样式
- Android的常见控件(TextView、EditText、Button、Menu)使用
- Struts menu的使用
- Android Menu的使用
- android的Menu使用
- android的Menu使用
- android的Menu使用
- android的Menu使用
- 软件日语第二课:工程表
- MasterPage技术 From YM的空间
- 软件日语第三课:周报
- 再谈工厂模式
- 通过windows live writer 在wordpress里撰写带图片的博文
- menu控件的使用
- 工艺指导
- 机械零件表面粗糙度的选择
- Pro/E超级技巧
- 24个字教你用好AutoCAD
- AutoCAD小技巧
- Auto CAD2004完全笔记
- 机械设计手册2[1].0的关于要插盘的问题的解密文件
- 不锈钢牌号对照表