asp.net.ph

SqlDataSource.FilterExpression Property

System.Web.UI.WebControls Namespace   SqlDataSource Class


.NET Framework version 2.0

Sets or retrieves a filtering expression that is applied when the Select method is called.

Syntax


Inline <asp:SqlDataSource filterexpression = strSQLExpression ... >
Script SqlDataSource.FilterExpression [ = strSQLExpression ]

Property Value


strSQLExpression A string that represents a filtering expression applied when data is retrieved using the Select method.

The property is read/write with no default value.

Exceptions


Exception Type Condition
NotSupportedException The FilterExpression property was set and the SqlDataSource is in DataReader mode.

Remarks

The syntax that is used for the FilterExpression property is a format string–style expression. The filter expression syntax is the same syntax that is accepted by the RowFilter property, because the filter expression is applied to the RowFilter property of the DataView object that is returned from executing the Select method. For more information, see Expression.

If you add parameters to the FilterParameters collection, you can also include format string placeholders ( for example, "{0}" ) in the expression to substitute for parameter values. The placeholders are replaced according to the index of the parameter in the FilterParameters collection.

You can include parameters in the FilterExpression property. If the parameter is a string or character type, enclose the parameter in single quotation marks. Quotation marks are not required, if the parameter is a numeric type.The FilterParameters collection contains the parameters that are evaluated for the placeholders that are found in the FilterExpression property.

The SqlDataSource control supports filtering data only when in the DataSet mode.

The FilterExpression property delegates to the FilterExpression property of the SqlDataSourceView object that is associated with the SqlDataSource control.

Example

The following example illustrates using the FilterExpression property in a typical search application.

<p>Search for &nbsp;<asp:textbox id = "searchBox" runat = "server" />
   <asp:button text = "Search" runat = "server" /></p>

<asp:gridview id = "searchGrid" runat = "server"
   datasourceid = "articles"
   ... />

<asp:sqldatasource id = "articles" runat = "server"
   connectionstring = "<%$ ConnectionStrings:aspnet %>" 
   selectcommand = "SELECT title, url, added, updated FROM aspx_articles ORDER BY title" 
   filterexpression = "title LIKE '%{0}%' or url LIKE '%{0}%'">

   <filterparameters>
      <asp:controlparameter controlid = "searchBox" propertyname = "Text" />
   </filterparameters>

</asp:sqldatasource>

The example above is what is actually used in the Site Search functionality provided in this workshop. The application allows users to search for articles using keywords.

 Show me 

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