• Asp.Net Repeater控件绑定泛型List<T>的用法之绑定二级repeater的方法


    前文有提到了如何在list<T>泛型中绑定了repeater的用法,今天在做项目的过程当中,又碰到了repeater的嵌套循环,二级repeater的绑定方法类似,关键点在于Datarow的一个类型转换。

    原代码:

    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Repeater dataList = e.Item.FindControl("Rpt2") as Repeater;
    DataRowView rowv = (DataRowView)e.Item.DataItem;
    int DepID = Convert.ToInt32(rowv["DepID"].ToString());
    dataList.DataSource = DbHelper.ExecuteTable("select * from CNVP_AdminDep where DepID=" + DepID + " and AdminID in (select AdminID from CNVP_AdminGroup Where GroupID in (17,18,19,20))");
    dataList.DataBind();
    }
    }

    现改为

    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Repeater dataList = e.Item.FindControl("SubDep") as Repeater;
    DepartmentModel rowv = (DepartmentModel)e.Item.DataItem;
    int DepID = rowv.DepartID;
    string Sql = " 1=1 and ParentID=" + DepID;
    DepartmentData bll1 = new DepartmentData();
    List<DepartmentModel> model1 = bll1.GetDepartmentList(Sql);
    if (model1 != null)
    {
    dataList.DataSource = model1;
    dataList.DataBind();
    }
    }
    }

  • 相关阅读:
    寒假补习记录_4
    寒假补习记录_3
    寒假补习记录_2
    寒假补习记录_1
    公文流转系统编程
    Javaweb编程
    转:在静态方法中访问类的实例成员
    Java字段初始化规律
    原码,反码,补码浅谈
    java第二节课课后
  • 原文地址:https://www.cnblogs.com/reddptp/p/3158194.html
Copyright © 2020-2023  润新知