Monday, January 5, 2009

Using Filter Expressions with an SQL Data Source in ASP.NET VB 2008

In Visual Studio 2008, we can filter the dataset in c# with out using sqlquery.

If you use sqldatasource in your project. we can filter the dataset in c# coding itself.

Example1

If (Session("FiltExp") <> Nothing) Then
SqlDataSource1.FilterExpression = Session("FiltExp").ToString()
End If

Example2

SqlDataSource1.FilterExpression = "city='" & DropDownList1.SelectedValue & "'"

Example3

SqlDataSource1.FilterExpression = "BirthDate > #" + dt + "#"
Session("FiltExp") = "BirthDate > #" + dt + "#"