OnItemCreated Method Of DataGrid

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?
 
W

wmain

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;
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top