<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("column_cat_id")%>' Visible="false"></asp:Label>
<li><a href="#"><%# Eval("column_cat_title")%></a>
<ul id="treeView" style='display:<%# getstyle(Eval("column_cat_id").ToString()) %>'>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<li><a href='product.aspx?id=<%#Eval("column_cat_id")%>' target="_parent"><img src="images/xiaohui.jpg" /><%#Eval("column_cat_title")%></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
这个事我的前台代码我像实现这样的效果
栏目1
栏目1-1
栏目1-2
栏目1-3
栏目1-4
栏目2
栏目2-1
栏目2-2
栏目2-3
栏目2-4
栏目3
栏目3-1
栏目3-2
栏目3-3
栏目3-4
所有的数据都是动态的这样的菜单
开始我用Jquery做但是每次刷新的时候不能保持状态
比如我点击栏目2一个子菜单项的时候按道理刷新后应该其他的两个栏目关闭只保持栏目2的菜单项,
但是每次刷新后都是只显示栏目1的菜单项,这个问题弄了很久大家帮帮忙
解决方案 »
- AjaxControlToolkit版本错误
- 怎么样遍历treeview的某一个层级的所有节点?
- ReflectedSchemas 文件太大的问题。
- 升级了!有两条叉穿了,散分!!!
- 关于CSS的问题请教大家。
- .Net 2.0高手请进~!!~!
- 我想把a页生成的sql语句传到b页。应该怎么传?怎么让地址栏里传过去的sql语句隐藏起来。请帮我看看。谢谢!
- 检测文件
- 没有为扩展名“”注册的生成提供程序。可以在 machine.config 或 web.config 中的 <compilation><buildProvider
- 求大数据多用户 数据库解决方案
- 类似于QQ留言编辑器,光标进去的时候才加载编辑器!
- asp.net中怎么把List<>里的值赋给数组
先建立一个left.aspx
代码如下<%@ Page Language="C#" AutoEventWireup="true" CodeFile="left.aspx.cs" Inherits="left" %>
<html>
<head>
<title>-后台管理</title>
<style type="text/css">
.ttl { CURSOR: pointer; COLOR: #ffffff; PADDING-TOP: 4px }
A:active{COLOR: #000000;TEXT-DECORATION: none}
A:hover{COLOR: #000000;TEXT-DECORATION: none}
A:link{COLOR: #000000;TEXT-DECORATION: none}
A:visited{COLOR: #000000;TEXT-DECORATION: none}
TD {
FONT-SIZE: 12px; FONT-FAMILY: "Verdana", "Arial", "细明体", "sans-serif"
}
.table_body {
BACKGROUND-COLOR: #EDF1F8;
height:18px;
CURSOR: pointer;
}.table_none {
BACKGROUND-COLOR: #FFFFFF;
height:18px;
CURSOR: pointer;
} </style> <script language="javascript">
function showHide(obj){
var oStyle = document.getElementById(obj).style;
oStyle.display == "none" ? oStyle.display = "block" : oStyle.display = "none";
}
</script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#9aadcd" leftmargin="0" topmargin="0">
<br>
<asp:Repeater ID="LeftMenu" runat="server" OnItemDataBound="LeftMenu_ItemDataBound">
<ItemTemplate>
<table cellspacing="0" cellpadding="0" width="159" align="center" border="0">
<tr>
<td width="23">
<img height="25" src="images/Menu/box_topleft.gif" width="23"></td>
<td class="ttl" onclick="JavaScript:showHide('M_<%# Eval("M_ID")%>');" width="129"
background="images/Menu/box_topbg.gif">
<%# Eval("M_Name")%>
</td>
<td width="7">
<img height="25" src="images/Menu/box_topright.gif" width="7"></td>
</tr>
</table>
<table id="M_<%# Eval("M_ID")%>" style="display: none" cellspacing="0" cellpadding="0"
width="159" align="center" border="0">
<tr>
<td background='images/Menu/box_bg.gif' height="0px" width='159' colspan='3'>
<table width="157" border="0" cellpadding="2" cellspacing="1">
<tbody>
<asp:Repeater ID="LeftMenu_Sub" runat="server">
<ItemTemplate>
<tr>
<td class="table_none" onclick="javascript:NowShow('M_<%# Eval("M_ID")%>','<%# Eval("M_Url")%>');" onmousemove="javascript:TDOverORIn('M_<%# Eval("M_ID")%>');" onmouseout="javascript:TDOverOROut('M_<%# Eval("M_ID")%>');" id="M_<%# Eval("M_ID")%>">
<img height='7' hspace='5' src='images/Menu/arrow.gif' width='5' align="bottom">
<%# Eval("M_Name")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="159" align="center" border="0">
<tr>
<td colspan="3">
<img height='10' src='images/Menu/box_bottom.gif' width='159'></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</body>
</html>
<script language="javascript">
var NowClickName="";
function NowShow(TopMenuName,Url)
{
document.getElementById(TopMenuName).className = "table_body";
if (NowClickName!="" &&NowClickName!=TopMenuName)
document.getElementById(NowClickName).className = "table_none";
NowClickName = TopMenuName;
//var o=window.open(url);
window.parent.frames["mainFrame"].location=Url;
//parment.mainFrame.src=Url;
}
function TDOverOROut(iname)
{
if (NowClickName!=iname)
{ document.getElementById(iname).className = "table_none"; }
}
function TDOverORIn(iname)
{
if (NowClickName != iname)
{
document.getElementById(iname).className = "table_body";
}
}
</script>
后台代码using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;//using Menu;
//using Menu.Components;
public partial class left : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindMenu();
} #region "绑定主菜单"
/// <summary>
/// 绑定主菜单
/// </summary>
private void BindMenu()
{ //2010年6月5日 封装动态菜单 //代码测试阶段 待封装2009-10-21
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=.;database=TESDB2000;uid=sa;pwd=sa";
string CommandText = "select * from Menu where M_Fid=0";//取出父菜单 数据库里的父ID为0
SqlCommand cmd = new SqlCommand(CommandText, cn);
SqlDataReader dr = null;
DataTable dt = new DataTable();
cn.Open();
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
}
#endregion #region "绑定子菜单"
/// <summary>
/// 绑定子菜单事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void LeftMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
int nParentID = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["M_ID"]);
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=.;database=TESDB2000;uid=sa;pwd=sa";
//取出父ID为nParentID 下的所有子项
string CommandText = "select * from Menu where M_Fid='" + nParentID + "'"; SqlCommand cmd = new SqlCommand(CommandText, cn);
SqlDataReader dr = null;
DataTable dt = new DataTable();
cn.Open();
using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(dr);
}
Repeater LeftSubID = (Repeater)e.Item.FindControl("LeftMenu_Sub");
LeftSubID.DataSource = dt;
LeftSubID.DataBind(); }
#endregion
}代码没有封装 你自己封装一下吧。然后可以在iframe中使使用此页做left。。
图片我正在传一会跟帖给地址
基于数据库的三级菜单实现(二级同理)
http://www.web521.com/asp/57468/T65733.shtml用层制作动态二级菜单
http://www.cnblogs.com/villison/archive/2007/09/26/906716.html
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cate_bind();
}
}
public void cate_bind()
{
adosql addproado = new adosql();
string sqlstr = "select category,categoryid from category";
DataSet test = addproado.todateset(sqlstr);
category.DataSource = test;
category.DataTextField = "category";
category.DataValueField = "categoryid";
category.DataBind(); }
public void category_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text =category.SelectedValue.ToString(); adosql cate_chang = new adosql();
string str_chang = "select sortsid,sortname from sorts where categoryid=" + category.SelectedValue.ToString();
sorts.DataSource = cate_chang.todateset(str_chang);
sorts.DataTextField = "sortname";
sorts.DataValueField = "sortsid";
sorts.DataBind();
}
}注意的是要在页面中将droplist控件添加属性autopostback=true
这个是什么意思啊???
但是我写window.parent.frames["product"].location=Url; 的时候出现脚本错误!window.parent.frames。product对象为空
纳闷了
我吧left。aspx作为左侧导航页面然后product.aspx是右边的页面内容页
<iframe id="mainFrame" name="mainFrame" style="height: 100%; visibility: inherit;
width: 100%; z-index: 1" scrolling="auto" frameborder="0" src="product.aspx"></iframe>
<head>
<title><%--<%=FrameName %>--%>小叶子</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.navPoint
{
font-family: Webdings;
font-size:9pt;
color:white;
cursor:pointer;
}
p{
font-size:9pt;
}.font_size { font-family: "Verdana", "Arial", "Helvetica", "sans-serif"; font-size: 12px; font-weight: normal; font-variant: normal; text-transform: none}
</style>
</head>
<body scroll="no" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<%
switch (MenuStyle)
{
case 0:
%>
<tr>
<td id="frmTitle" name="frmTitle" nowrap="nowrap" valign="middle" align="center"
width="198" style="border-right: 1px solid #000000">
<iframe name="BoardTitle" style="height: 100%; visibility: inherit; width: 198; z-index: 2"
scrolling="auto" frameborder="0" src="left.aspx"></iframe>
</td>
<td style="width: 10pt" bgcolor="#7898A8" title="关闭/打开左栏" class="navPoint">
<table border="0" cellpadding="0" cellspacing="0" width="11" height="100%" align="right">
<tr>
<td valign="middle" align="right" class="middleCss" style="width: 13px">
<img border="0" src="images/Menu/close.gif" id="menuimg" alt="隐藏左栏" onmouseover="javascript: menuonmouseover();"
onmouseout="javascript: menuonmouseout();" onclick="javascript:switchSysBar()"
style="cursor: hand" width="11" height="76" /></td>
</tr>
</table>
</td>
<td style="width: 100%">
<iframe id="mainFrame" name="mainFrame" style="height: 100%; visibility: inherit;
width: 100%; z-index: 1" scrolling="auto" frameborder="0" src="Product.aspx"></iframe>
</td>
</tr>
<%
break;
case 1:
%>
<%--测试--%>
<%
break;
case 2:
%>
<%-- 测试--%>
<%
break; }
%> </table>
</body>
</html>
<script language="JavaScript" type="text/javascript">var DispClose = true;function CloseEvent()
{
if (DispClose)
{
return "是否离开当前页面?";
}
}
window.onbeforeunload=CloseEvent;
rnd.today=new Date(); rnd.seed=rnd.today.getTime(); function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280; return rnd.seed/(233280.0); }; function rand(number) { return Math.ceil(rnd()*number); };
function AlertMessageBox(Messages)
{
DispClose = false;
window.location.href = location.href+"?"+rand(1000000);
alert(Messages);
}
var var_frmTitle = document.getElementById("frmTitle");
var var_menuimg = document.getElementById("menuimg");function switchSysBar(){ if (var_frmTitle.style.display=="none") {
var_frmTitle.style.display=""
var_menuimg.src="images/Menu/close.gif";
var_menuimg.alt="隐藏左栏"
}
else {
var_frmTitle.style.display="none"
var_menuimg.src="images/Menu/open.gif";
var_menuimg.alt="开启左栏"
}
} function menuonmouseover(){
if (var_frmTitle.style.display=="none") {
var_menuimg.src="images/Menu/open_on.gif";
}
else{
var_menuimg.src="images/Menu/close_on.gif";
}
}
function menuonmouseout(){
if (var_frmTitle.style.display=="none") {
var_menuimg.src="images/Menu/open.gif";
}
else{
var_menuimg.src="images/Menu/close.gif";
}
}
if(top!=self)
{
top.location.href = "default.aspx";
}
</script>
<iframe id="mainFrame" name="mainFrame" style="height: 100%; visibility: inherit;
width: 100%; z-index: 1" scrolling="auto" frameborder="0" src="Product.aspx"></iframe>
</td>Product.aspx改成你右边要显示的内容.