• Repeater 嵌套


    //页面
    <asp:Repeater ID="parentRepeater" runat="server">
                <ItemTemplate>
                    <b>
                        <%# DataBinder.Eval(Container.DataItem, "CatelogName")%></b><br>
                    <asp:Repeater ID="childRepeater" runat="server" DataSource='<%# ((DataRowView)Container.DataItem)
          .Row.GetChildRows("myrelation") %>'>
                        <HeaderTemplate>
                            <table>
                                <tr>
                                    <th>
                                        ProductName
                                    </th>
                                    <th>
                                        ProductDescription
                                    </th>
                                </tr>
                            </table>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <%# DataBinder.Eval(Container.DataItem, "["ProductName"]")%>
                            <%# DataBinder.Eval(Container.DataItem, "["ProductDescription"]")%><br>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:Repeater>
    //后台 .aspx.cs
      DataSet ds = ProductDao.test();
     
              ds.Relations.Add("myrelation", ds.Tables["Category"].Columns["CatelogID"],
             ds.Tables["Product"].Columns["CatelogID"]);
                parentRepeater.DataSource = ds.Tables["Category"];
                Page.DataBind();
    ---------------------
    //ProductDao.cs
    public static DataSet test()
            {
                string connStr = @"Data Source=.;Initial Catalog=Test;Integrated Security=True";
     
                string sql = @"select CatelogID, [CatelogName]
      from [T_WAP_Product]
      group by CatelogID,CatelogName";
                DataSet ds = new DataSet();
                SqlDataAdapter sqlAdapter = new SqlDataAdapter();
                using (SqlConnection connection = new SqlConnection(connStr))
                {
    //前后两次填充dateset
                    sqlAdapter.SelectCommand = new SqlCommand(sql, connection);
                    sqlAdapter.Fill(ds, "Category");
     
                    sql = @"select *
    FROM dbo.T_WAP_Product";
                    sqlAdapter.SelectCommand = new SqlCommand(sql, connection);
                    sqlAdapter.Fill(ds, "Product");
     
                    return ds;
                }
            }
  • 相关阅读:
    鼠标移向小图显示大图
    一个简单漂亮的CSS相册代码
    windows 应该关闭服务
    NetBIOS名称
    DOS命令大全(经典收藏)
    大揭露:Win中也有各种不老实的服务
    变量名
    ASP.NET2.0 GridView小技巧汇粹 (转)
    Dfs实战技术
    windows 2003中活动目录支持文件
  • 原文地址:https://www.cnblogs.com/Amity/p/3153393.html
Copyright © 2020-2023  润新知