mike mcintyre's

.N e t J o u r n a l

vbCity Blogs moved to:
http://cs.vbcity.com/blogs
  Home :: Syndication  :: Login

OctNovember 2009Dec
SMTWTFS
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Archives

Topics

Source Code

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 on Thursday, August 17, 2006 4:42 PM