惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
有赞技术团队
有赞技术团队
Jina AI
Jina AI
H
Help Net Security
D
Docker
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
B
Blog RSS Feed
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MongoDB | Blog
MongoDB | Blog
美团技术团队
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
IT之家
IT之家

博客园 - Na57

ASP.NET MVC应用中一个诡异错误的处理 使用Enterprise Library 4.0 Logging 的问题 8. Action过滤 6. 视图和生成助手 5. 控制器和Action方法 2. 创建基本的MVC项目 3. URL路由 - Na57 - 博客园 4. 用MVC实现URL路由 Google笔记本迈向烂笔头 XML and Databases 笔记 烂笔头又来了 - Na57 - 博客园 <程序员>200711期算法擂台的解答 GeoServer抛异常IllegalArgumentException的原因 CSS学习 关于CSS中float属性的理解 《SAML简介:安全地共享数字身份信息》读后感 JavaScript 学习(2) - JS的内建对象 JavaScript from C#(入门篇) 2006.6《程序员》笔记
ItemCreated与ItemDataBound
Na57 · 2006-11-02 · via 博客园 - Na57

最近使用Repeater的时候遇到一个问题.页面上有一个Repeater,并为其添加了一个ItemCreated事件:

    protected void Repeater2_ItemCreated(object sender, RepeaterItemEventArgs e)

    {

        if (e.Item.ItemType == ListItemType.Item)

        {

            Label body = e.Item.FindControl("lbBody") as Label;

            string bodyText = ((Post)e.Item.DataItem).Body;

            if (bodyText.Length > 20)

            {

                body.Text = bodyText.Substring(0, 20) + "……";

            }

            else

                body.Text = bodyText;

        }

}

目的是为了在显示数据的时候对数据做一点改动.

但是,每当页面回调的时候就会出现问题: DataItem为空值.最后才发现,ItemCreatedItemDataBound是有区别的:

ItemCreated在每次Repeater Render的时候都会调用,ItemDataBound则不一定,只有调用了DataBind(),需要进行数据绑定的时候才会调用.

切记!