repeater 三级嵌套

话不多说,上图先。

前台代码:

<table cellpadding="0" cellspacing="1" width="100%"> <asp:Repeater ID="rptClass" runat="server" onitemdatabound="rptClass_ItemDataBound"> <ItemTemplate> <tr style=" height:30px;" mce_style=" height:30px;"> <td colspan="5" style=" color:#000; font-size:14px; font-weight:bold;" mce_style=" color:#000; font-size:14px; font-weight:bold;"> <%#Eval("JobName") %> </td> </tr> <asp:Repeater ID="rptsClass" runat="server" onitemdatabound="rptsClass_ItemDataBound"> <ItemTemplate> <tr style=" background-color:#d9e9ff; height:24px; padding-top:2px;"> <td style=" font-weight:bold; color:#000;" mce_style=" font-weight:bold; color:#000;"> <%#Eval("FuncName")%> </td> <asp:Repeater ID="rptShowJob" runat="server"> <ItemTemplate> <td οnmοusemοve=" this.style.backgroundColor='#d5b760'; this.style.color='#fff'" οnmοuseοut="this.style.backgroundColor='';this.style.color='';"> <%# Eval("FuncSubName")%> </td> </ItemTemplate> </asp:Repeater> </tr> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> </table> 

后台代码:

//第一级绑定 private void bindRpt() { string sql = ""; sql = "SELECT * FROM jobtemplates"; rptClass.DataSource = sssDB.GetDataTable(sql); rptClass.DataBind(); } //绑定层级 protected void rptClass_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string preid = ((DataRowView)e.Item.DataItem).Row["id"].ToString(); //获得对应ID Repeater bsClass = (Repeater)e.Item.FindControl("rptsClass"); //找到要绑定数据的Repeater if (bsClass != null) { string sqlstr = "SELECT DISTINCT(FuncName),FuncCate FROM admfunc WHERE FID=" + preid + " "; bsClass.DataSource = sssDB.GetDataTable(sqlstr); bsClass.DataBind(); } } } //绑定职们信息 protected void rptsClass_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string cid = ((DataRowView)e.Item.DataItem).Row["FuncCate"].ToString(); //获得对应ID Repeater rptShowJob = (Repeater)e.Item.FindControl("rptShowJob"); //找到要绑定数据的Repeater if (rptShowJob != null) { string sqlstr = "SELECT FuncSubName FROM admfunc WHERE FuncCate='" + cid + "' ORDER BY FuncCate"; rptShowJob.DataSource = sssDB.GetDataTable(sqlstr); rptShowJob.DataBind(); } } }  

数据库关系图

 数据库数据

转载于:https://www.cnblogs.com/Renn/archive/2009/12/15/2048386.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值