区域表(ID,name) 省份表(区域ID外键,省份名)
Repeater1 把每个区域查询出来,Repeater2每个区域的ID 查询出相应的省份,
死的HTML 效果图
我瞎写的代码
<div class="menu">
<ul>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourceQuyu">
<ItemTemplate>
<li><a class="hide" href="###"><%# Eval("region")%></a>
<ul>
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSourceQuyu2">
<ItemTemplate>
<li><a href="###"><%# Eval("province")%></a></li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu2" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =<%# Eval("id")%>' ></asp:SqlDataSource>
//我想根据上一级的id查到此
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
</ul>
</div>
看了一些网上的代码,搞不懂,好像还要写后台???
13 个解决方案
#1
附个样式,跑起来也能看到效果
<style type="text/css">
/* common styling */
.menu {font-family: arial, sans-serif; width:106px; height:150px; position:relative; margin:0; float:left; font-size:13px;}
.menu ul li a, .menu ul li a:visited {display:block; text-decoration:none; color:#000;width:104px; height:20px; text-align:center; color:#fff; border:1px solid #aaa; background:#4085F7; line-height:20px; font-size:11px; overflow:hidden;}
.menu ul {padding:0; margin:0;list-style-type: none; }
.menu ul li {float:left; margin-right:1px; position:relative;}
.menu ul li ul {display: none;}
/* specific to non IE browsers */
.menu ul li:hover a {color:#fff; background:#36f;}
.menu ul li:hover ul {display:block; position:absolute; top:0; left:105px; width:105px;}
.menu ul li:hover ul li a.hide {background:#6a3; color:#fff;}
.menu ul li:hover ul li:hover a.hide {background:#6fc; color:#000;}
.menu ul li:hover ul li ul {display: none;}
.menu ul li:hover ul li a {display:block; background:#eee; color:#000;}
.menu ul li:hover ul li a:hover {background:#6fc; color:#000;}
.menu ul li:hover ul li:hover ul {display:block; position:absolute; left:105px; top:0;}
</style>
#2
RegionProduct 省份表
Region 区域表
Region 区域表
#3
总之就是想做个2级菜单,repeater嵌套
#5
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
这些还是写到后台去吧,易于维护修改,也让前台代码看起来整洁一些
#6
我把问题整理一下,解决这个传值问题就OK了
//2级菜单,
<asp:SqlDataSource ID="SqlDataSourceQuyu2" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] = <%# Eval("id")%>' ></asp:SqlDataSource>
<%# Eval("id")%>是上一级的数据,我想让SqlDataSourceQuyu2动态化。但这么写运行后进入页面报错,我把 where [RegionId] =<%# Eval("id")%> 去掉就不报错了,但没有筛选,不是我要的效果,求解怎么改,哪里写错了?
#7
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =<%# Eval("id")%>'
说白了我这里怎么动态化?where [RegionId] =<%# Eval("id")%>
#8
这个报错
#9
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
#10
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
问题就是我不知到怎么换个写法。。。<%# Eval("id")%>这个换成啥?解决就结贴
#11
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
问题就是我不知到怎么换个写法。。。<%# Eval("id")%>这个换成啥?解决就结贴
直接写成上一级查询ID的SQL语句, where [RegionId] in (查询上一级ID)
#12
SelectCommand='<%# "SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =" + Eval("id") %>'
#13
谢了,各位问题刚刚解决了
#1
附个样式,跑起来也能看到效果
<style type="text/css">
/* common styling */
.menu {font-family: arial, sans-serif; width:106px; height:150px; position:relative; margin:0; float:left; font-size:13px;}
.menu ul li a, .menu ul li a:visited {display:block; text-decoration:none; color:#000;width:104px; height:20px; text-align:center; color:#fff; border:1px solid #aaa; background:#4085F7; line-height:20px; font-size:11px; overflow:hidden;}
.menu ul {padding:0; margin:0;list-style-type: none; }
.menu ul li {float:left; margin-right:1px; position:relative;}
.menu ul li ul {display: none;}
/* specific to non IE browsers */
.menu ul li:hover a {color:#fff; background:#36f;}
.menu ul li:hover ul {display:block; position:absolute; top:0; left:105px; width:105px;}
.menu ul li:hover ul li a.hide {background:#6a3; color:#fff;}
.menu ul li:hover ul li:hover a.hide {background:#6fc; color:#000;}
.menu ul li:hover ul li ul {display: none;}
.menu ul li:hover ul li a {display:block; background:#eee; color:#000;}
.menu ul li:hover ul li a:hover {background:#6fc; color:#000;}
.menu ul li:hover ul li:hover ul {display:block; position:absolute; left:105px; top:0;}
</style>
#2
RegionProduct 省份表
Region 区域表
Region 区域表
#3
总之就是想做个2级菜单,repeater嵌套
#4
http://www.cnblogs.com/zmxmiss/archive/2009/02/26/1398635.html 参考一下呗,显示用jquery显示隐藏
#5
区域(东北,华北,西北)是一级菜单,省份(沈阳,广东)是二级菜单
区域表(ID,name) 省份表(区域ID外键,省份名)
Repeater1 把每个区域查询出来,Repeater2每个区域的ID 查询出相应的省份,
死的HTML 效果图
我瞎写的代码
<div class="menu">
<ul>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourceQuyu">
<ItemTemplate>
<li><a class="hide" href="###"><%# Eval("region")%></a>
<ul>
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSourceQuyu2">
<ItemTemplate>
<li><a href="###"><%# Eval("province")%></a></li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu2" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =<%# Eval("id")%>' ></asp:SqlDataSource>
//我想根据上一级的id查到此
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
</ul>
</div>
看了一些网上的代码,搞不懂,好像还要写后台???
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
这些还是写到后台去吧,易于维护修改,也让前台代码看起来整洁一些
#6
区域(东北,华北,西北)是一级菜单,省份(沈阳,广东)是二级菜单
区域表(ID,name) 省份表(区域ID外键,省份名)
Repeater1 把每个区域查询出来,Repeater2每个区域的ID 查询出相应的省份,
死的HTML 效果图
我瞎写的代码
<div class="menu">
<ul>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourceQuyu">
<ItemTemplate>
<li><a class="hide" href="###"><%# Eval("region")%></a>
<ul>
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSourceQuyu2">
<ItemTemplate>
<li><a href="###"><%# Eval("province")%></a></li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu2" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =<%# Eval("id")%>' ></asp:SqlDataSource>
//我想根据上一级的id查到此
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
</ul>
</div>
看了一些网上的代码,搞不懂,好像还要写后台???
<asp:SqlDataSource ID="SqlDataSourceQuyu" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand="SELECT * FROM [Region]"></asp:SqlDataSource>
这些还是写到后台去吧,易于维护修改,也让前台代码看起来整洁一些
我把问题整理一下,解决这个传值问题就OK了
//2级菜单,
<asp:SqlDataSource ID="SqlDataSourceQuyu2" runat="server"
ConnectionString="<%$ ConnectionStrings:zidaiHaiyang %>"
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] = <%# Eval("id")%>' ></asp:SqlDataSource>
<%# Eval("id")%>是上一级的数据,我想让SqlDataSourceQuyu2动态化。但这么写运行后进入页面报错,我把 where [RegionId] =<%# Eval("id")%> 去掉就不报错了,但没有筛选,不是我要的效果,求解怎么改,哪里写错了?
#7
SelectCommand='SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =<%# Eval("id")%>'
说白了我这里怎么动态化?where [RegionId] =<%# Eval("id")%>
#8
这个报错
#9
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
#10
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
问题就是我不知到怎么换个写法。。。<%# Eval("id")%>这个换成啥?解决就结贴
#11
这个报错
换个写法吧,<%# Eval("id")%>直接写成上一级查询ID的SQL语句试试,报错是因为页面的<asp:SqlDataSource>中不允许出现<%# Eval("id")%>
问题就是我不知到怎么换个写法。。。<%# Eval("id")%>这个换成啥?解决就结贴
直接写成上一级查询ID的SQL语句, where [RegionId] in (查询上一级ID)
#12
SelectCommand='<%# "SELECT [RegionId], [ProductName], [province] FROM [RegionProduct] where [RegionId] =" + Eval("id") %>'
#13
谢了,各位问题刚刚解决了