asp.net.ph

DataView.RowStateFilter Property

System.Data Namespace   DataView Class


Sets or retrieves the row state filter used in the DataView.

Syntax


Script DataView.RowStateFilter [ = enumValue ]

Property Value


enumValue One of the DataViewRowState values.

The property is read/write with no default value.

Remarks

Only rows that have been deleted using the Delete method will have their RowStateFilter value set to Deleted. Those rows added using the AddNew method will similarly have the property set to New.

NOTE: Using the Remove method of the DataRowCollection class does not mean that a row will be marked as Deleted. Use the Delete method instead to ensure such rows can be viewed in the DataView.

New rows will also be visible when the RowStateFilter is set to ModifiedCurrent or CurrentRows.

Deleted rows will also be visible when the RowStateFilter is set to ModifiedOriginal and OriginalRows.

Example

The following example initializes a DataTable with a single column, then changes the data and sets the RowStateFilter of the DataView to display different row sets, depending on the DataViewRowState.

private void DemonstrateRowState ( ) {
   int i;
   // create a DataTable with one column.
   DataTable myTable = new DataTable ( "myTable" );
   DataColumn myColumn = new DataColumn ( "myColumn" );
   myTable.Columns.Add ( myColumn );
   // add ten rows.
   DataRow myRow;
   for ( i = 0;i < 10 ; i++ ) {
      myRow = myTable.NewRow ( );
      myRow [ "myColumn" ] = "item " + i;
      myTable.Rows.Add ( myRow );
  }
   myTable.AcceptChanges ( );
   // create a DataView with the table.
   DataView myView = new DataView ( myTable );
   // change one row's value:
   myTable.Rows [ 1 ] [ "myColumn" ] = "Hello";
   // add one row:
   myRow = myTable.NewRow ( );
   myRow [ "myColumn" ] = "World";
   myTable.Rows.Add ( myRow );
   // set the RowStateFilter to display only new and modified rows.
   myView.RowStateFilter = DataViewRowState.New | 
      DataViewRowState.ModifiedCurrent;
   // print those rows. Output = "Hello" "World";
   PrintView ( myView, "ModifiedCurrent and New" );
   // set filter to display on originals of modified rows.
   myView.RowStateFilter = DataViewRowState.ModifiedOriginal;
   PrintView ( myView,"ModifiedOriginal" );
   // delete three rows.
   myTable.Rows [ 1 ].Delete ( );
   myTable.Rows [ 2 ].Delete ( );
   myTable.Rows [ 3 ].Delete ( );
   // set the RowStateFilter to display only new and modified rows.
   myView.RowStateFilter = DataViewRowState.Deleted;
   PrintView ( myView,"Deleted" );
   //Set filter to display only current.
   myView.RowStateFilter = DataViewRowState.CurrentRows;
   PrintView ( myView,"Current" );
   // set filter to display only unchanged rows.
   myView.RowStateFilter = DataViewRowState.Unchanged; 
   PrintView ( myView,"Unchanged" );
   // set filter to display only original rows.
   myView.RowStateFilter = DataViewRowState.OriginalRows ; 
   PrintView ( myView,"OriginalRows" );
}

private void PrintView ( DataView dv,string label ) {
   Response.Write ( "<br>" + label );

   for ( int i = 0;i < dv.Count ; i++ ) {
      Response.Write ( dv [ ] [ "myColumn" ] );
   }
}
  C# VB

See Also

DataView Members   DataViewRowState   AddNew   Delete 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