asp.net.ph

GridViewRow.DataItem Property

System.Web.UI.WebControls Namespace   GridViewRow Class


.NET Framework version 2.0

Sets or retrieves the row of data associated with a GridViewRow.

Syntax


Script GridViewRow.DataItem [ = var ]

Property Value


var Object representing the underlying data row to which the GridViewRow is bound.

The property is read/write with no default value.

NOTE: This property applies only to data rows in the GridView control.

Remarks

Use the DataItem property to specify or determine the properties of the data row associated with a GridViewRow object in a GridView control.

DataItem is mainly used to retrieve field values from the row in the data source associated with a GridViewRow.

NOTE: The DataItem property is available only during the RowDataBound event of a GridView control, and is discarded after.

Example

The following example demonstrates how to use the DataItem property to retrieve a field value in a GridViewRow.

  1. Create a handler for the RowDataBound event.
    void setBindings ( Object src, GridViewRowEventArgs e ) {
       ...
    }
  2. In the event handler, do the following:
    1. Test for a data row to make sure that you are working with a data-bound row and not a header or footer.
    2. if ( e.Row.RowType == DataControlRowType.DataRow ) {
         ...
      }
    3. Create a DataRowView object ( when data source mode is a DataSet ) or an IDataRecord object ( when data source mode is a DataReader ) and set its value to the DataItem for the current grid row.
      DataRowView rowView = ( DataRowView ) e.Row.DataItem;

      NOTE: The DataItem property is typed as an object, which must be cast to the appropriate type.

    4. From the DataRowView object, extract the data value you need to examine.
    5. if ( rowView [ "url" ].ToString ( ).IndexOf ( "demos" ) > -1 )
Using the SqlDataSource.FilterExpression Property
Run Sample | View Source
See Also

GridViewRow Members   DataItemIndex   RowIndex 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