View Single Post
  #5 (permalink)  
Old June 14th, 2009, 04:24 PM
Lee Dumond's Avatar
Lee Dumond Lee Dumond is offline
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts

Two reasons for the problem you're having:

1. The Eval method just evaluates the databinding method. It does not allow you to change the value.

2. The ItemDataBound event is too late to change any of the values anyway, because they are already bound when this event fires.

In order to do this, you need to handle the ItemCreated event. Then, you need to modify the DataRowView that is being used to display the item.

protected void listProducts_ItemCreated(object sender, ListViewItemEventArgs e)
   if (e.Item.ItemType == ListViewItemType.DataItem)
      ListViewDataItem dataItem = (ListViewDataItem) e.Item;
      string prodtype = (string) DataBinder.Eval(dataItem.DataItem, "ProductType");
      DataRowView view = (DataRowView)dataItem.DataItem;
      if (prodtype == "Sample")
         view["ProductText"] = "Sample product";
Visit my blog at
Follow me on Twitter:

if (this.PostHelpedYou)