OnItemCreated Method Of DataGrid

  • Thread starter Thread starter rn5a
  • Start date Start date
R

rn5a

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?
 
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.FindControl 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.RowState | DataControlRowState.Edit ==
DataControlRowState.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">The Client GridView object.</param>
/// <param name="e">The GridViewRowEventArgs used to the the row
being updated.</param>
protected void gvClients_RowCreated(object sender,
GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
{
if (row.RowState == DataControlRowState.Alternate ||
row.RowState == DataControlRowState.Normal)
{
BulletedList lstIdentification =
(BulletedList)row.FindControl("lstIdentifications");
BulletedList lstRecipient =
(BulletedList)row.FindControl("lstRecipients");
lstIdentification.Items.Clear();
lstRecipient.Items.Clear();
if
((LDVComputers.BusinessEntities.Client)e.Row.DataItem != null)
{
int SaveClientId = ClientId;
ClientId =
((LDVComputers.BusinessEntities.Client)e.Row.DataItem).ClientId;
foreach
(LDVComputers.BusinessEntities.Identification identification in
_presenter.Identifications())
lstIdentification.Items.Add(new
ListItem(identification.IdentificationName + ": " +
identification.IdentificationNumber,
identification.IdentificationId.ToString()));
foreach (LDVComputers.BusinessEntities.Recipient
recipient in _presenter.Recipients())
lstRecipient.Items.Add(new
ListItem(recipient.RecipientFirstName + " " +
recipient.RecipientLastName, recipient.RecipientId.ToString()));
ClientId = SaveClientId;
}
}
}
}
 
Back
Top