zoukankan      html  css  js  c++  java
  • 获取repeater控件模版列中的控件

    理论:

    直接用repeater.Findcontrol是获取不到子控件的,因为子空间实际是在ItemTemplate中的,翻译一个评论:
    if(Roles.IsUserInRole("admin"))
    {
    Button delete = (Button)rptNotering.Items[0].FindControl("btnDelete");
    delete.Visible = true;
    Button edit = (Button)rptNotering.Items[0].FindControl("btnEdit");
    edit.Visible = true;
    }

    Inside a repeater are 0-many Items. .Items[x] is where x is the index of the specific itemtemplate instance.
    If your repeater returns 10 rows of data, then your repeater returns an instance of ItemTemplate 10 times
    and places each instance in the Items[] collection.

    Your findcontrol method is not looking inside the ItemTemplate.
    Hope this helps :-)


    大体意思是
    :在repeater中有0项,Items[x] 才是制定模版列的实例,如果你的repeater有10行数据,那么你的repeater返回10次ItemTemplate 的实例,每个实例都是在item的集合众的。

    所以我在事件中作了,效果还是可以,只不过这样的循环感觉不是很好,还有注意你要在repeater数据邦定后再来做如上操作,否则没效果的。。。。

    实例:

            for (int i = 0; i < rpList.Items.Count; i++)
            {
                chk = (CheckBox)rpList.Items[i].FindControl("CheckBox1");
                Response.Write("<script>alter('"+chk.Text+"')</script>");
            }

  • 相关阅读:
    ChromeDriver下载
    LR基础理论详解
    python中assert详解
    python定义类()中写object和不写的区别
    python list初始化技巧
    python list中append()方法和extend()方法区别
    python生成器(generator)、迭代器(iterator)、可迭代对象(iterable)区别
    使用__slots__节省python内存技巧
    lambda表达式详解
    python处理数据问题详解
  • 原文地址:https://www.cnblogs.com/wangpei/p/1315689.html
Copyright © 2011-2022 走看看