动态下拉菜单的简单实现

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

首先在aspx文件中加入如下代码:

< script

function openMenu(cur)//显示菜单

{

eval("menu"+cur+".style.visibility='visible'")

//alert(menu1)

}

function closeMenu(cur)//隐藏菜单

{

eval("menu"+cur+".style.visibility='hidden'")

}

< /script

< td class="lcolhead" onmouseover='openMenu("1")' style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px"

onmouseout='closeMenu("1")'

//添加一个列

< A onmouseover='openMenu("1")' onmouseout='closeMenu("1")' href="#"

大生产作品< /A

//定义一个单独的层

< div class="unnamed1" id="Layer1" style="Z-INDEX: 1; LEFT: 0px; WIDTH: 0px; POSITION: relative; TOP: -2px; HEIGHT: 0px"

//定义一个菜单

< div id="menu1" onmouseover='openMenu("1")' style="Z-INDEX: 2; LEFT: 0px; VISIBILITY: hidden; POSITION: absolute; TOP: 0px" onmouseout='closeMenu("1")'

//添加一个表,容纳菜单

< table id=Table1 cellSpacing=1 cellPadding=1 width=120 border=0 align =center

< tr

< td align=center

//加入DataGrid控件,并添加一列做菜单,将数据库中数据读出与此列邦定写形成菜单

< asp:DataGrid id=DataGrid1 runat="server" AutoGenerateColumns="False" ShowHeader="False" BorderWidth="0px"

< ItemStyle BorderColor="Transparent"

< /ItemStyle

//加入链接列

< Columns

< asp:HyperLinkColumn DataNavigateUrlField="ID"

DataNavigateUrlFormatString="http://localhost/Taile/Creativity/WebForm1.aspx?id={0}"

//显示数据库中的Name字段

DataTextField="Name"

< HeaderStyle Width="120px"

< /HeaderStyle

< ItemStyle Font-Italic="True"

< /ItemStyle

< /asp:HyperLinkColumn

< /Columns

< /asp:DataGrid

< /td

< /tr

< /table

< /div

< /div

< /td class=lcolhead

以上是aspx文件中要添加的代码

然后在aspx.cs文件中将数据读出邦定到datagrid1上即可用数据库中的Name字段来形成下菜单

如:

protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

DataView UserProductDataView=new DataView();

//获得数据库视图

UserProductDataView=(new UserProductBF()).GetUserProductType();

DataGrid1.DataSource=UserProductDataView;

DataGrid1.DataBind();

}

运行即可

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航