On Apr 13, 5:56 pm, r...@rediffmail .com wrote:
In the .NET2.0 SDK Documentation, the DataGrid's OnItemCreated method
is described as thus:
The ItemCreated event is raised when an item in the DataGrid control
is created, both during round-trips and at the time data is bound to
the control.
Can someone please explain what does the above line mean preferably
with examples?
This is usually used when you are templating controls and need to set
them up. In this case you would use the e.row.FindContr ol method to
locate the template control using it's ID. You will need to convert
the Control returned by FindControl into the actual control type. Some
of the properties of the row that are useful for this is the RowType
and the RowState. The RowType of the row tells you if it is a header,
data or footer row. The RowState of the row tells you if the row is an
Edit, normal or alternate row. A warning, when looking for the Edit
row, you need to mask out the Edit type because it also has either the
normal or alternate enum value as well
If(e.row.RowSta te | DataControlRowS tate.Edit ==
DataControlRowS tate.Edit)
{
...
}
a complete example ...
/// <summary>
/// Update the Recipient list and the Identification list in the
Client GridView's Normal or Alternate rows.
/// </summary>
/// <param name="sender">T he Client GridView object.</param>
/// <param name="e">The GridViewRowEven tArgs used to the the row
being updated.</param>
protected void gvClients_RowCr eated(object sender,
GridViewRowEven tArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowT ype.DataRow)
{
if (row.RowState == DataControlRowS tate.Alternate ||
row.RowState == DataControlRowS tate.Normal)
{
BulletedList lstIdentificati on =
(BulletedList)r ow.FindControl( "lstIdentificat ions");
BulletedList lstRecipient =
(BulletedList)r ow.FindControl( "lstRecipients" );
lstIdentificati on.Items.Clear( );
lstRecipient.It ems.Clear();
if
((LDVComputers. BusinessEntitie s.Client)e.Row. DataItem != null)
{
int SaveClientId = ClientId;
ClientId =
((LDVComputers. BusinessEntitie s.Client)e.Row. DataItem).Clien tId;
foreach
(LDVComputers.B usinessEntities .Identification identification in
_presenter.Iden tifications())
lstIdentificati on.Items.Add(ne w
ListItem(identi fication.Identi ficationName + ": " +
identification. IdentificationN umber,
identification. IdentificationI d.ToString()));
foreach (LDVComputers.B usinessEntities .Recipient
recipient in _presenter.Reci pients())
lstRecipient.It ems.Add(new
ListItem(recipi ent.RecipientFi rstName + " " +
recipient.Recip ientLastName, recipient.Recip ientId.ToString ()));
ClientId = SaveClientId;
}
}
}
}