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项目

    
  • 相关阅读:
    【Demo 0062】文件遍历
    【Demo 0068】获取分区信息
    【Demo 0060】记录个人信息
    【Demo 0069】文件读写
    【Demo 0064】监控文件/目录变更
    【Demo 0067】文件类型关联图标
    【Demo 0065】获取被修改的文件/目录
    【Demo 0062】目录及文件基本操作
    【Demo 0061】打开与保存文件
    【Demo 0066】监控被变更文件/目录(完成端口)
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1838372.html
Copyright © 2011-2022 走看看