mike mcintyre's

.N e t J o u r n a l

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

JulAugust 2006Sep
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

Archives

Topics

Source Code

Thursday, August 17, 2006 #

Accessing data has evolved in ASP.NET to include new controls such as the SqlDataSource control. The SqlDataSource class provides a FilterExpression property that can be used to filter the results of calling the SqlDataSource class' Select method.

The code example that follows is all the code needed to drive a web page where a user can enter part or all of a last name to filter the rows of a GridView:

Code Example

Partial Class _Default

    Inherits System.Web.UI.Page

 

    Protected Sub setFilterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles setFilterButton.Click

        Me.SetFilter()

    End Sub

 

    Protected Sub SetFilter()

        Dim filterExpression As String = "LastName LIKE '" & Me.filterTextBox.Text & "*'"

        Response.Write("Filter expression in effect is: " & filterExpression)

        Me.AccessDataSource1.FilterExpression = filterExpression

    End Sub

 

    Protected Sub clearFilterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearFilterButton.Click

        Me.filterTextBox.Text = ""

        Me.SetFilter()

    End Sub

 

    Protected Sub X()

        Dim filterExpression As String = "LastName LIKE 'Gr'"

        Me.AccessDataSource1.FilterExpression = filterExpression

        Me.AccessDataSource1.

 

    End Sub

End Class

Click the link below to download ASP source code and Visual Basic source code in a Microsoft Visual Studio 2005 ASP.NET 2.0 solution which demonstrates how to use the SqlDataSource FilterExpression property to filter the rows displayed in an ASP.NET 2.0 GridView.

 Filter SqlDataSource Select Method Call

posted @ 4:42 PM