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

    
  • 相关阅读:
    actionscript3.0 的一些小技巧
    Flash 安全沙箱的意义
    明明连上了网,但是打不开网页
    关于电脑上可用内存太小的问题
    AS3 Starling 学习杂谈 (一) Quad类
    更新flash builder4,6 的AIR版本
    软件工程实践2017第二次作业
    软件工程实践2017第一次作业
    微信小程序开发指南合集 各类组件用法技巧
    微信小程序视频教程合集 附带源码、PPT下载
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1838372.html
Copyright © 2011-2022 走看看