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>");
            }

  • 相关阅读:
    计算机中的那些缩写词
    Linux 下dns的搭建
    html中的定位
    编程基础之流程控制
    linux中kvm的安装及快照管理
    zabbix 中监控windows 的typepref中的值
    详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
    rhel7 单用户修改root密码
    Linux vim编辑器使用详解
    Linux下用ftp更新web内容!
  • 原文地址:https://www.cnblogs.com/wangpei/p/1315689.html
Copyright © 2011-2022 走看看