zoukankan      html  css  js  c++  java
  • Repeater控件备忘

    Repeater控件一般用来显示数据,通常会关闭试图状态,但是当用来做表单输入栏目时,就需要开启视图状态,并且通常需要去遍历Repeater.Items集合,通过FindControl来找到需要的控件,并获取用户的输入。

    ---------

    Repeater的事件:

    ItemCreated

        在里面动态设置子控件的值(比方设置一个 Literal.Text="<input type='radio' ..." )时,ViewState是不会保留的,这个时候控件树并没完全建立,值的改变不会保留下来。

        另外ItemCreated,在第一次与PostBack时多会被执行,

        而只有在ItemDataBound只在DataBind时会被执行(通常是第一次访如果PostBack不触发DataBind的话)

     //======参考代码

    private RepeaterItem CreateItem(int itemIndex, ListItemType itemType, bool dataBind, object dataItem)
    {
        RepeaterItem item = this.CreateItem(itemIndex, itemType);
        RepeaterItemEventArgs e = new RepeaterItemEventArgs(item);
        this.InitializeItem(item);
        if (dataBind)//只有在dataBind情况下,ItemCreated处理程序里才能使用被绑定的数据
        {
            item.DataItem = dataItem;
        }
        this.OnItemCreated(e);//事件处理程序是在这里被调用的
        this.Controls.Add(item);//而到这里才会启动RepeaterItem的ViewState

                //(通过StateBag.TrackViewState,注意Control的TrackViewState是internal的)
        if (dataBind)
        {
            item.DataBind();
            this.OnItemDataBound(e);
            item.DataItem = null;
        }
        return item;
    }
     

    //=============

    ItemDataBound

         在里面动台设置子控件的值,会在ViewState中正常保存下来

    -------------------------------

    Repeater.Items集合中只包括 列表项目,无法获取Footer项目

    
  • 相关阅读:
    Salesforce学习笔记(一)
    踏上Salesforce的学习之路(二)
    踏上Salesforce的学习之路(一)
    Salesforce注册开发者账号
    ubuntu下安装rtl8811cu/rtl8821cu网卡 Tplink WDN5200H网卡
    基于JRebel开发的MySQL Explain插件
    Logback配置解析
    基于springboot实现http响应异常信息国际化
    高并发场景下请求合并的实践
    后台开发常用mysql语句_v1.0
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1838372.html
Copyright © 2011-2022 走看看