Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Data Value From ListView ItemDataBound

Tags:

c#

asp.net

I'm sure I've done this before but really cant remember how.

In the ItemDataBound event of a ListView I need to get the actual data value. I cant seem to find it in the ListViewItemEventArgs object that gets passed in.

Thanks

like image 224
Gavin Avatar asked Oct 19 '09 12:10

Gavin


3 Answers

Use the ListViewDataItem in the ItemDataBound event:

protected void yourListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        YourDataSource yourDataSource= (YourDataSource )dataItem.DataItem;            

    }

}
like image 172
rick schott Avatar answered Nov 01 '22 00:11

rick schott


I think what you're after is the ListViewDataItem.DataItem

like image 37
stuartd Avatar answered Oct 31 '22 22:10

stuartd


protected void Score_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewItem)
    {
        RadListViewDataItem item = e.Item as RadListViewDataItem;
        object dataItem = ((System.Data.DataRowView)(((RadListViewDataItem)e.Item).DataItem)).Row.ItemArray[2].ToString();
        string raetest = Convert.ToString(dataItem);
    }
}
like image 31
El Mas Avatar answered Nov 01 '22 00:11

El Mas