Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemDataBound 'e.item.dataitem("key")' with ListView Control [duplicate]

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?

like image 266
Fermin Avatar asked May 20 '26 01:05

Fermin


1 Answers

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.

like image 109
Adam Nofsinger Avatar answered May 21 '26 14:05

Adam Nofsinger