zoukankan      html  css  js  c++  java
  • 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();
    }
    }
    }

  • 相关阅读:
    python-列表生成式
    python-迭代
    python接口自动化测试-requests下载图片
    python接口自动化测试-requests请求异常处理
    python接口自动化测试-requests.get()
    什么是单元测试?如何做好单元测试?
    Elasticsearch 6 Mapping设置
    git pull报“unable to update local ref”解决方式
    Artifactory 简介
    maven项目版本管理
  • 原文地址:https://www.cnblogs.com/reddptp/p/3158194.html
Copyright © 2011-2022 走看看