asp.net中Repeater嵌套绑定的方法(查询新闻类别和新闻类别下的新闻) ._.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > asp.net中Repeater嵌套绑定的方法(查询新闻类别和新闻类别下的新闻) .

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

 2013/7/12 11:19:25  林玲  博客园  我要评论(0)
  • 摘要:前台页面:<divclass="llgh_2"><asp:RepeaterID="Repeater1"runat="server"onitemdatabound="Repeater1_ItemDataBound"><ItemTemplate><tablewidth="100%"align="center"cellpadding="5"cellspacing="0"border="0"class="tal"><tr><
  • 标签:.net ASP.NET 方法 Repeater net

前台页面:

<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();

 

        }

结果如图:

发表评论
用户名: 匿名