在 DataBound 事件上获取绑定到 ListView 的数据 [英] Get data being bound to ListView on DataBound event

查看:23
本文介绍了在 DataBound 事件上获取绑定到 ListView 的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView 控件,并且我在控件中添加了一个 DataBound 事件(不知道这是否正确).

I have a ListView control and I have added a DataBound event (don't know if this is the correct one) to the control.

我想从该事件访问绑定到该特定 ItemTemplate 的数据,这可能吗?

I'm wanting to access the data being bound to that particular ItemTemplate from this event, is that possible?

推荐答案

C# 解决方案

protected void listView_ItemDataBound(object sender, ListViewItemEventArgs e)
{        
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        ListViewDataItem dataItem = (ListViewDataItem)e.Item;
        // you would use your actual data item type here, not "object"
        object o = (object)dataItem.DataItem; 
    }
}

为什么他们让 ListView 如此不同仍然让我感到困惑.不过肯定是有原因的.

Why they made this so different for ListView still sort of puzzles me. There must be a reason though.

这篇关于在 DataBound 事件上获取绑定到 ListView 的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆