UseOnitemdataboundMethod provisionItemdataboundCustom Event ProcessingProgram.
When the item is bound to the DataGrid ControlItemdataboundEvent. This event provides you with the last chance to access a data item before the client displays it. When this event is triggered, the data item is set to null and no longer available. We can use it to display the corresponding data and set other necessary information.
ItemdataboundAnother typical application of events is to implement computing domains.
Example:
<Asp: DataGrid id = datalist1 runat = "server"Onitemdatabound= "Computefield".../>
In the specified computefield event:
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
Double unitsinstock = convert. todouble (E. Item. Cell [2]. Text );
Double unitprice = convert. todouble (E. Item. Cell [4]. Text );
E. Item. Cell [5]. Text = string. Format ("{0: c}", unitsinstock * unitprice );
If (unitsinstock = 0) E. Item. cssclass = "outofdata ";
}
Outofdatais the CSS style defined in style.css.
. Outofdata
{
Color: red;
}