62,041
社区成员
发帖
与我相关
我的任务
分享
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium"
ForeColor="#990000" Orientation="Horizontal" StaticSubMenuIndent="10px"
onmenuitemclick="Menu1_MenuItemClick">
<StaticSelectedStyle BackColor="#FFCC66" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#990000" BorderStyle="Solid" ForeColor="White" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<DynamicItemTemplate>
<%# Eval("Text") %>
</DynamicItemTemplate>
<DynamicSelectedStyle BackColor="#FFCC66" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
<StaticItemTemplate>
<%# Eval("Text") %>
</StaticItemTemplate>
</asp:Menu>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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;
using System.Data.SqlClient;
public partial class menu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/*
说明,待写
*/
if(Session["logid"]==null)
{
Response.Redirect("login.aspx");
}else
{ // 用户验证后合格者,且在回话期内,拟构建菜单树
// Response.Write("功能菜单,用户:" + Session["login"].ToString());
String mySel = "select distinct(功能组名) from 功能表 where 功能id in (select 功能id from 用户权限表 where 用户id in (select 用户id from 用户表 where loginname= '" + Session["logid"].ToString() + "')) order by 功能组名 desc";
SqlConnection conn = new SqlConnection(SqlDataSource1.ConnectionString);
SqlDataAdapter SQLDA = new SqlDataAdapter(mySel,conn);
conn.Open();
SqlDataReader SQLDR = SQLDA.SelectCommand.ExecuteReader();
Menu1.Items.Clear();
this.Menu1.Orientation = Orientation.Horizontal;
String GM;
while (SQLDR.Read())
{
GM = SQLDR["功能组名"].ToString();
MenuItem mi = new MenuItem();
mi.Text = GM;//菜单根项加一
String mySel2 = "select * from 功能表 where 功能id in (select 功能id from 用户权限表 where 用户id in (select 用户id from 用户表 where loginname= '" + Session["logid"].ToString() + "')) and 功能组名='"+GM+"' and inuse = '在用'";
SqlConnection conn2 = new SqlConnection(SqlDataSource1.ConnectionString);
SqlDataAdapter SQLDA2 = new SqlDataAdapter(mySel2, conn2);
conn2.Open();
SqlDataReader SQLDR2 = SQLDA2.SelectCommand.ExecuteReader();
while (SQLDR2.Read())
{
MenuItem mii = new MenuItem();
mii.Text = SQLDR2["功能名"].ToString();
mii.NavigateUrl = SQLDR2["url"].ToString();
mii.Value = SQLDR2["功能名"].ToString();
mi.ChildItems.Add(mii);
}
this.Menu1.Items.Add(mi);
SQLDR2.Close();
conn2.Close();
} ;
this.Menu1.Dispose();
SQLDR.Close();
conn.Close();
}
}
}
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
Session["MenuItemClicked"]=e.Item.Value;
}
中,设断电,发现程序根本就没进来。也就是说,这个事件没被激发。Phillip Williams
Add MenuItems that do not set a value for the NavigateUrl property.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.menuitemclick(VS.80).aspx
--
HTH,
Phillip Williams
while (SQLDR2.Read())
{
MenuItem mii = new MenuItem();
mii.Text = SQLDR2["功能名"].ToString();
mii.NavigateUrl = SQLDR2["url"].ToString();
mii.Value = SQLDR2["功能名"].ToString();
mi.ChildItems.Add(mii);
}