首先在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();
}
运行即可