asp.net.ph

DataRow.Item Property ( String )

System.Data Namespace   DataRow Class


Sets or retrieves the data stored in the column specified by name.

Syntax


Object variable = DataRow.Item [ columnName ];
... or ...
Object variable = DataRow [ columnName ];
  C# VB JScript

Parameters

columnName
The name of the column.

Property Value

An Object that contains the data.

Exceptions


Exception Type Condition
IndexOutOfRangeException Occurs when the column specified by columnName can not be found.
InvalidCastException Occurs when setting a value and its Type does not match DataType.
DeletedRowInaccessibleException Occurs when attempting to set a value on a deleted row.

Remarks

When setting the property, an exception will be thrown if an exception occurs in the ColumnChanging event. If this is an immediate edit, see EndEdit for the exceptions that can be thrown.

Example

The following examples demonstrate using the second syntax of the Item property to get or set the value of a given column name in a specified row.

Navigating thru the Rows of a DataTable
Run Sample | View Source
DataList Editing Command Events Example
Run Sample | View Source

In the first example, tblSource.Rows [ rowIndex-1 ] returns the reference to the DataRow, and PlanId is the column name. The returned value is then used to set the RowFilter of the default DataView associated with the parent DataTable of the row.

DataView getView ( int rowIndex ) {
   DataTable tblSource = ( DataTable ) Session [ "tblSource" ];
   tblSource.DefaultView.RowFilter = "PlanID='" + tblSource.Rows [ rowIndex-1 ] [ "PlanId" ] + "'";
   return tblSource.DefaultView;
}
  C# VB

In the second example, myTable.Rows [ .Item.ItemIndex ] returns the reference to the DataRow, and the row values are then set from user input.

// get and update row
DataRow myRow = myTable.Rows [ .Item.ItemIndex ];
myRow [ "ContactName" ] = contact;
myRow [ "ContactTitle" ] = title;
myRow [ "Address" ] = address;
myRow [ "City" ] = city;
myRow [ "Phone" ] = phone;
myTable.AcceptChanges ( );
  C# VB

See Also

DataRow Members   DataRow.Item Overload List 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