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

  • 相关阅读:
    一.创建型模式 Factory
    Tcp/Ip I/O函数
    Tcp/Ip协议理解_简单实例
    Tcp/Ip协议理解_3
    Tcp/Ip协议理解_2
    Tcp/Ip协议理解_1
    abp+angular+bootstrap-table的使用
    Abp mvc angular 添加视图
    Abp添加菜单
    JS 获取一串路径中的文件名称
  • 原文地址:https://www.cnblogs.com/wangpei/p/1315689.html
Copyright © 2011-2022 走看看