请教数据绑定的问题
一张分类表 cate(catid,catname,parentid)大概数据是这样的 catid catname parentid
1 房产交易 0
2 物品交易 0
3 企业招聘 0
4 出租房 1
5 二手房 1
6 合租房 1
7 二手台式电脑 2
8 二手笔记本 2
9 二手包包 2
10 文秘 3
11 技工 3
12 电脑网络相关 3
数据结构大致就这样 想实现这样一个功能
绑定数据 用repeater 或者随便什么都行
房产交易
二手房 合租房 出租房
物品交易
二手台式电脑 二手笔记本 二手包包
企业招聘
文秘 技工 电脑网络相关
之前看过论坛的案例,那数据是存储在两个表
用两个repeater做的
这个是存储在一个表里的
--------------------编程问答-------------------- repeater 嵌套 repeater
select top 3 xxx 总分类 外层 repeater
select xxx from xxx where catid = parentid 子分类 内层 repeater
--------------------编程问答--------------------
正解 --------------------编程问答-------------------- 使用嵌套 --------------------编程问答-------------------- 可以使用repeater嵌套 --------------------编程问答-------------------- 嗯,就用嵌套就行了 --------------------编程问答-------------------- 控件嵌套! --------------------编程问答-------------------- 使用嵌套就可以了 --------------------编程问答--------------------
顶上 --------------------编程问答-------------------- 前台代码
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="fold.ascx.cs" Inherits="Admin_WebUserControl_fold" %>
<style type="text/css">
.menu_list {
width: 150px;
}
.menu_head {
padding: 8px 10px;
cursor: pointer;
position: relative;
margin: 1px;
font-weight: bold;
background: #93cdff;
}
.menu_body {
display: none;
}
.menu_body a {
padding: 8px 0px;
display: block;
color: #006699;
background-color: #EFEFEF;
padding-left: 10px;
font-weight: bold;
text-decoration: none;
}
.menu_body a:hover {
color: #7fb2f4;
background-color: #dfdfdf;
text-decoration: underline;
}
</style>
<script type="text/javascript" language="javascript">
$(function(){
$("#firstpane p.menu_head").click(function()
{
$(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
});
$("#firstpane p.menu_head").mouseover(function()
{
$(this).css({background:"#2286c6"});
});
$("#firstpane p.menu_head").mouseout(function()
{
$(this).css({background:"#93cdff"});
});
// $("#firstpane div:first").show();
$("#firstpane div:eq(0)").show();
})
</script>
<div id="firstpane" class="menu_list">
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<p class="menu_head">
<asp:HyperLink runat="server" ID="hl" Text='<%#Eval("sname") %>'></asp:HyperLink><asp:Label ID="Label1" runat="server" Text='<%#Eval("sid") %>' Visible="false"></asp:Label></p>
<div class="menu_body">
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<a href=""><%#Eval("sname") %></a>
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
后台代码
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
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;
public partial class Admin_WebUserControl_fold : System.Web.UI.UserControl
{
Stypes stype = new Stypes();
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
bing2();
}
else
{
bing();
}
}
private void bing()
{
IList<Stypes> list = stype.selectStypesBysname();
Repeater1.DataSource = list;
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = (Repeater)e.Item.FindControl("repeater2");
//DataRowView dr = (DataRowView)e.Item.DataItem;
int sid = Convert.ToInt32((e.Item.FindControl("Label1") as Label).Text);
DataTable dt = stype.selectStypesBysnum(sid);
rep.DataSource = dt;
rep.DataBind();
(e.Item.FindControl("hl") as HyperLink).NavigateUrl = "Default2.aspx?id=" + sid;
//String str = (e.Item.FindControl("hl") as HyperLink).NavigateUrl = "Default2.aspx?id=" + sid;
//int sid = Convert.ToInt32(dr["sid"]);
}
}
private void bing2()
{
int id = Convert.ToInt32(Request.QueryString["id"]);
IList<Stypes> list = stype.selectStypesByTnum(id);
Repeater1.DataSource = list;
Repeater1.DataBind();
}
}
引用个jquery.1.4.js就行了,我这个是个用户控件
--------------------编程问答-------------------- 楼上说用repeater嵌套比较简单,但是楼主说了他所有数据都在一张表上,建议如果数据量不大的话就重新建表用repeater嵌套把,如果数据量很大,期待牛人来给出更好的办法…… --------------------编程问答-------------------- 在一张表里也可以过滤不同的内容作为数据源 嵌套帮顶啊
呵呵 帮顶啊 repeater嵌套就可以实现了
补充:.NET技术 , ASP.NET