Reapter嵌套实现多级分类效果

 

前台:

 <div id="category_tree">
                <asp:repeater ID="Parent" runat="server">
                  <itemtemplate>
                   <dl>
                      <dt><a href='<%# "ParentInfo.aspx?ParentId="+ Eval("Id") %>' style="text-decoration:none;"><%# DataBinder.Eval(Container.DataItem, "CategoryName")%></a></dt>
                        <asp:repeater ID="Child" DataSource='<%# Eval("myrelation")%>' runat="server">
                    <itemtemplate>
                    <dd><a href='<%# "ChildrenInfo.aspx?childrenId="+ Eval("Id") %>' style="text-decoration:none;"><%# DataBinder.Eval(Container.DataItem, "[\"CategoryName\"]")%></a></dd>
                    </itemtemplate>
                    </asp:repeater>                    </dl>
                    </itemtemplate>
             </asp:repeater>      
                </div>

样式:

 #category_tree{border:4px solid #f1faff; background-color:#fff;padding-bottom:13px;padding-top:5px}
   #category_tree dl{margin:6px; text-align:left;}
   #category_tree dt{background:url(../Content/Images/DefaultImages/lineBg.gif) repeat-x left bottom;
   color:#3f3f3f;  padding:2px 0 3px 12px;
   }
   #category_tree dt a{background:url(../Content/Images/DefaultImages/bg.gif) no-repeat 0 -69px;
   color:#3f3f3f; padding-left:15px; text-decoration:none;
   }
   #category_tree dd{padding:3px 0 3px 10px;float:left;width:75px;overflow: hidden; }
   #category_tree dd a{color:#404040; text-decoration:none;}
   #category_tree dd a:hover{color:#ff6600; text-decoration:none;}

 

 

后台:

               con = new SqlConnection(sqlCon);
                //查询父类
                SqlCommand cmd1 = new SqlCommand("select * from CategoryInfo where ParentCateId is null", con);
                SqlDataAdapter dad1 = new SqlDataAdapter(cmd1);
                DataSet ds = new DataSet();
                dad1.Fill(ds, "parentCategory");
                //查询子类
                SqlCommand cmd2 = new SqlCommand("select * from CategoryInfo where ParentCateId is not null", con);
                SqlDataAdapter dad2 = new SqlDataAdapter(cmd2);
                dad2.Fill(ds, "ChildCategory");
                ds.Relations.Add("myRelation", ds.Tables["parentCategory"].Columns["Id"], ds.Tables["ChildCategory"].Columns["ParentCateId"]);

                this.Parent.DataSource=ds;

                this.Parent.DataBind();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值