zoukankan      html  css  js  c++  java
  • 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;
                }
            }
  • 相关阅读:
    Hexo博客系列(二)-在多台机器上利用Hexo发布博客
    Hexo博客系列(一)-Windows系统配置Hexo v3.x个人博客环境
    [原创]VMware Workstation 14.1.3 Pro安装CentOS_7.6.1810
    [原创]前后端交互的方式整理
    [转载]白素贞的身世之谜
    [原创]存储过程里面的递归
    [原创]SpringBoot上传图片踩的坑
    [原创]markdown语法学习(commonmark)
    使用IntelliJ IDEA 前最好修改的配置
    软件开发资源下载
  • 原文地址:https://www.cnblogs.com/Amity/p/3153393.html
Copyright © 2011-2022 走看看