Repeater嵌套的两种方案

aspx中:

<asp:Repeater id="repLM" runat="server">

    <ItemTemplate>

        <table border="0" style="BORDER-COLLAPSE: collapse" width="98%" id="table8" class="list">

            <tr>

                <td colspan="2">

                    <div align="center">

                        <table border="0" style="BORDER-COLLAPSE: collapse" width="100%" id="table9">

                            <tr>

                                <td class="listTop"> <img src="<%=strStylePath%>dot2.gif"> <%# DataBinder.Eval(Container.DataItem,"ClassName") %></td>

                            </tr>

                            <tr>

                                <td>

                                    <table border="0" style="border-collapse: collapse" width="100%" id="table10">

                                        <asp:Repeater id="repWZ" runat="server">

                                            <ItemTemplate>

                                                <tr>

                                                    <td><img border="0" src="<%=strStylePath%>list.gif" width="15" height="6"><a href='Show.aspx?AtcID=<%# DataBinder.Eval(Container.DataItem,"AtcID") %>'><font color='<%# DataBinder.Eval(Container.DataItem,"TitleColor") %>'><%# DataBinder.Eval(Container.DataItem,"Title") %></font></a>

                                                    </td>

                                                </tr>

                                            </ItemTemplate>

                                        </asp:Repeater>

                                    </table>

                                </td>

                            </tr>

                        </table>

                    </div>

                </td>

            </tr>

            <tr>

                <td width="87%">

                </td>

                <td width="12%" class="more"><span lang="zh-cn">更多</span></td>

            </tr>

        </table>

    </ItemTemplate>

</asp:Repeater>


//先邦定栏目

string strSQL1="select ClassID,ClassName from xClass where ParentID=0 and PageID="+strPageID;

SqlDataAdapter da1=new SqlDataAdapter(strSQL1,myConn);

da1.Fill(ds,"LM");

repLM.DataSource=ds.Tables["LM"].DefaultView;

repLM.DataBind();        

myConn.Close();


 
在外面的Repeater的ItemDataBound事件里写如下程序:
 
private void repLM_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)

{

    

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 

    { 

        Repeater rpColumnNews = (Repeater) e.Item.FindControl("repWZ"); 

        //找到分类Repeater关联的数据项 

        DataRowView rowv = (DataRowView)e.Item.DataItem; 

        //提取分类ID 

        string strClassID = Convert.ToString(rowv["ClassID"]); 

        //里面的Repeater

        string strSQL2="select xArticle.AtcID,xArticle.Title,xArticle.TitleColor from xArticle,xClass where ";

        strSQL2+=" (xArticle.ClassID=xClass.ClassID and xClass.ClassID="+strClassID+") or (xArticle.ClassID=xClass.ClassID and xClass.ParentID="+strClassID+")";

        SqlDataAdapter da2=new SqlDataAdapter(strSQL2,myConn);

        ds=new DataSet();

        da2.Fill(ds,"WZ");

        rpColumnNews.DataSource=ds.Tables["WZ"].DefaultView;

        rpColumnNews.DataBind();        

        myConn.Close();

    } 



}

你可能感兴趣的:(r)