• Repeater双重绑定(子菜单前台代码:)


    前台代码:

    View Code
    <asp:Repeater ID="parentRepeater" runat="server" OnItemDataBound="parentRepeater_ItemDataBound" Visible=false>

    <ItemTemplate>

    <b>一级:

    <%# DataBinder.Eval(Container.DataItem,"categorytitle") %>

    </b>

    <br>

    <!-- 子Repeater开始 -->

    <asp:Repeater ID="childRepeater" runat="server">

    <ItemTemplate>

    二级:

    <%# DataBinder.Eval(Container.DataItem, "newstitle")%>

    <br>

    </ItemTemplate>

    </asp:Repeater>

    <!-- 子Repeater结束 -->

    </ItemTemplate>

    </asp:Repeater>

     

    后台代码:

    View Code
    protected void Page_Load(object sender, EventArgs e)

    {

    SqlDataAdapter sda = new SqlDataAdapter("select * from newscategory", con);

    DataSet ds = new DataSet();

    sda.Fill(ds, "table1");

    DataTable dt = new DataTable();

    DataView dv = new DataView(ds.Tables["table1"]);

    }

    protected void parentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)

    {

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

    {

    Repeater r2 = (Repeater)e.Item.FindControl("childRepeater");

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

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

    //提取分类ID

    string CategorieId = Convert.ToString(rowv["categoryid"]);

    //根据分类ID查询该分类下的产品,并绑定产品Repeater

    string sql = "select distinct top 6 newstitle from newscontent,newscategory where newscontent.categoryid = '" + CategorieId + "'";

    SqlDataAdapter sda = new SqlDataAdapter(sql, con);

    DataSet ds = new DataSet();

    sda.Fill(ds, "table2");

    r2.DataSource = ds.Tables["table2"].DefaultView;

    r2.DataBind();

    }

    }


  • 相关阅读:
    es6箭头函数
    微信小程序入门
    浏览器常见错误代码
    nginx学习
    windows下mongodb安装与使用整理
    mongodb简单的增删改查
    github入门到上传本地项目
    Robomongo
    对象(面向对象、创建对象方式、Json)
    代码编辑器——Visual Studio Code
  • 原文地址:https://www.cnblogs.com/ishibin/p/2312259.html
Copyright © 2020-2023  润新知