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

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

问题描述

我有一个ListView控件和我添加了一个DataBound事件(不知道这是否是正确的)来控制。

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


解决方案

C#的解决方案

 保护无效listView_ItemDataBound(对象发件人,ListViewItemEventArgs E)
{
    如果(e.Item.ItemType == ListViewItemType.DataItem)
    {
        ListViewDataItem的DataItem =(ListViewDataItem)e.Item;
        //你会用你的实际数据项类型在这里,没有对象
        对象o =(对象)dataItem.DataItem;
    }
}

他们为什么做出了这样的ListView如此不同还有几分困惑了我。必须有一个原因,但。

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

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

解决方案

C# Solution

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; 
    }
}

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

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

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