जगदीश खोलिया: May 2011

Monday, May 2, 2011

Differences Between ItemCreated, ItemDataBound and ItemCommand


Differences Between ItemCreated, ItemDataBound and ItemCommand

The important events raised by DataGrid, DataList, Repeater
  • ItemCreated
  • ItemDataBound
  • ItemComman
When
a datagrid, datalist or repeater is bound to a data source say a
dataset it consists of tables and each table consists of data rows. For
each record in the DataSource, a new DataWebControlNameItem instance is
created and appended to the Web Control. After the
DataWebControlNameItem has been created, its dataitem property is set to
the value of the current DataSource record.

The ItemCreated
event fires once for every DataWebControlNameItem added to the data Web
control. It fires before the DataWebControlNameItem's DataItem property
is assigned.

The ItemDataBound event also fires once for every
DataWebControlNameItem added to the data Web control, but this event
fires after the DataWebControlNameItem's DataItem property is assigned.


Finally, the ItemCommand event fires whenever the Command event for a
Button or LinkButton within the data Web control fires.