views:

980

answers:

2

I have a datalist i want to programmatically run some checks and then change the text that is been displayed. Can this be done ? Any examples?

A: 

You can do your calculations and checks on datalist control's data source (datatable, collection, ... etc.). Also you can programmatically change the values of the items that datalist display by updating the datasource of the datalist.

An alternative way is using ItemDataBound event. Here in MSDN you can see an example.

Canavar
thanks man!!! You saved me :)
ferronrsmith
+1  A: 

The DataList has an ItemDataBound event which signals the addition of each item in the list. By subscribing to this event can process each item data being added.

Server control:

<asp:DataList id="ItemsList"
       ...
       OnItemDataBound="ItemDataBound"
       runat="server">

Code behind:

protected void ItemDataBound(Object sender, DataListItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.Item || 
       e.Item.ItemType == ListItemType.AlternatingItem)
   {
       //process item data
   }
}

You can find specific details about the event and parameters in the MSDN Library

Mircea Grelus