且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取数据绑定到ListView中的数据绑定事件

更新时间:2022-10-15 07:42:37

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.