asp.net.ph

DataGrid.ItemCreated Event

System.Web.UI.WebControls Namespace   DataGrid Class


Occurs when an item is created in the DataGrid control.

[ VB ]
Public Event ItemCreated As DataGridItemEventHandler

[ C# ]
public event DataGridItemEventHandler ItemCreated;

[ C++ ]
public: __event DataGridItemEventHandler* ItemCreated;

In [ JScript ], you can handle the events defined by a class, but you cannot define your own.

Remarks

The DataGrid control is structurally composed of an assortment of rows called items. You can have up to seven different types of items in a DataGrid: normal and alternating data items, a header, a pager, a footer, the currently selected item, and the item that is currently being edited.

When any of these items are created, the DataGrid control fires an ItemCreated event, against which you can write an appropriate handler.

This event provides an opportunity to access each item before the page is finally sent to the client for display. After this event is raised, the item is then bound to data and the ItemDataBound event in turn is raised, after which the data item is nulled out and no longer available.

Event Data

Information related to the ItemCreated event is passed via a DataGridItemEventArgs object to the method assigned to handle the event. The following DataGridItemEventArgs property provides information specific to this event.

Property Description
Item Gets the DataGridItem associated with the event.

Example

The following example illustrates a way to handle the ItemCreated event of a DataGrid. In this case, the sample sets the style properties of the specified button type in a ButtonColumn, as each item is created.

The below snippet shows how to attach a handler for the event.

<asp:datagrid id = "myDataGrid" runat = "server" onItemCreated = "setButtonStyle" ... >

The below shows how the handler method is defined.

void setButtonStyle ( Object src, DataGridItemEventArgs e ) {
   if ( e.Item.ItemType == ListItemType.Item || 
         e.Item.ItemType == ListItemType.AlternatingItem ) {
      TableCellCollection myCells = e.Item.Cells;
    ( ( Button ) myCells [ 3 ].Controls [ 0 ] ).CssClass = "add";
    ( ( Button ) myCells [ 4 ].Controls [ 0 ] ).CssClass = "remove";
   }
}

 Show me 

See Also

DataGrid Members   ItemDataBound   DataGridItemEventHandler Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph