asp.net.ph

DataView.RowFilter Property

System.Data Namespace   DataView Class


Sets or retrieves the expression used to filter which rows are viewed in the DataView.

Syntax


Script DataView.RowFilter [ = strExpression ]

Property Value


strExpression A string that specifies how rows are to be filtered.

The property is read/write with no default value.

Remarks

To form a RowFilter value, specify the name of a column followed by an operator and a value to filter on. The value must be set in quotes. For example:

myView.RowFilter = "LastName = 'Smith'"

See the DataColumn class's Expression property for more information.

Example

The following examples demonstrate using the RowFilter property to programmatically "filter" the records in a DataView at run time, based on user input.

Filtering a DataView
Run Sample | View Source
Paging thru RowFilter Results
Run Sample | View Source
Filtering for a Single Row
Run Sample | View Source

The first example shows how to dynamically retrieve a set of records from a DataTable, given a RowFilter based on user input.

DataView myView = ( ( DataTable ) Session [ "tblGear" ] ).DefaultView;
myView.RowFilter = "Description LIKE '%" + strSearch.Text + 
   "%' or Model LIKE '%" + strSearch.Text + "%' ";
  C# VB

The second example is basically the same, except that the result sets are rendered into a DataGrid, with paging controls automatically enabled when the record count is more than the specified page size.

int found = myView.Count;
...
myGrid.Visible = ( found > 0 );
myGrid.PagerStyle.Visible = ( found > myGrid.PageSize );
  C# VB

The last example shows how to use RowFilter to return a single record. tblSource.DefaultView returns the reference to the DataView, the RowFilter value of which is set using a column value ( PlanId ) from a dynamically specified row.

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

See Also

DataView Members   Expression   Sort 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