asp.net中Repeater嵌套绑定的方法(查询新闻类别和新闻类别下的新闻) .

前台页面:

<div class="llgh_2">
                    <asp:Repeater ID="Repeater1" runat="server"
                        onitemdatabound="Repeater1_ItemDataBound">
                        <ItemTemplate>
                            <table width="100%" align="center" cellpadding="5" cellspacing="0" border="0" class="tal">
                                <tr>
                                    <td colspan="2">
                                        <h4>
                                            <%# DataBinder.Eval(Container.DataItem, "typename")%>
                                        </h4>
                                    </td>
                                </tr>
                                <asp:Repeater ID="rptProduct" runat="server">
                                    <ItemTemplate>
                                        <tr>
                                            <td class="td_r">
                                               <a href='ProductInfo.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "typeid") %>'>
                                               <%# DataBinder.Eval(Container.DataItem, "title")%>
                                            </td>
                                            <td class="td_rr">
                                                <%# DataBinder.Eval(Container.DataItem, "regdate")%>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </table>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>

后台代码(部分代码):

//在绑定新闻类别时,绑定新闻类别下的新闻

//新闻类别名称Repeater1绑定省略,正常绑定即可,下面代码为新闻类别名称Repeater1的ItemDataBound事件

 

 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rptProduct = (Repeater)e.Item.FindControl("rptProduct");
            //找到新闻类别编号
            object CategorieId = DataBinder.Eval(e.Item.DataItem, "typeid");
            //根据新闻类别ID查询该分类下的新闻,并绑定新闻

           //rptProduct.DataSource =获取产品列表的方法(参数:Convert.ToString(CategorieId));

            rptProduct.DataSource =newsbll.GetAllNewsId(Convert.ToInt32(CategorieId));
            rptProduct.DataBind();

 

        }

结果如图:

转载于:https://www.cnblogs.com/linling/p/3185589.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值