Filtering dynamically

Dynamic filtering is one of the most powerful ways to turn a Telerik ASP.NET RadGrid from a static data viewer into an interactive, responsive tool your users actually enjoy working with. Whether you’re shaping filters on the fly, combining multiple conditions, or driving the grid from external controls, dynamic filtering gives you precision without clutter and flexibility without complexity.

Related Articles

... and you 'll find more on the Telerik ASPNET Grid Menu

Ending up spending quite a bit of time on this, finally discovered I needed to disable linq expressions in the grid header. The rest of it is pretty straightforward

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Height="600px" EnableLinqExpressions="false"  >

Sub applyfilters()
    Dim strError As String = ""
    Try
 
        'get the values of the text boxes
        Dim strPONumberFilter As String = txtPONumberFilter.Text.Trim()
        Dim strVendorNameFilter As String = txtVendorNameFilter.Text.Trim()
        Dim strItemNumberFilter As String = txtItemNumberFilter.Text.Trim()
        Dim mtv = RadGrid1.MasterTableView
 
        ' Build the filter expression dynamically
        Dim parts As New List(Of String)
 
        If strPONumberFilter <> "" Then
            parts.Add("(PONUMBER LIKE '%" & strPONumberFilter.Replace("'", "''") & "%')")
        End If
 
        If strVendorNameFilter <> "" Then
            parts.Add("(VENDNAME LIKE '%" & strVendorNameFilter.Replace("'", "''") & "%')")
        End If
 
        If strItemNumberFilter <> "" Then
            parts.Add("(ITEMNMBR LIKE '%" & strItemNumberFilter.Replace("'", "''") & "%')")
        End If
 
        ' Join with AND so both filters apply
        mtv.FilterExpression = String.Join(" AND ", parts)
 
        ' Sync Telerik column filter UI
        Dim colPONumber = mtv.GetColumnSafe("PONUMBER")
        colPONumber.CurrentFilterValue = strPONumberFilter
        colPONumber.CurrentFilterFunction = If(strPONumberFilter = "", GridKnownFunction.NoFilter, GridKnownFunction.Contains)
 
        Dim colVendName = mtv.GetColumnSafe("VENDNAME")
        colVendName.CurrentFilterValue = strVendorNameFilter
        colVendName.CurrentFilterFunction = If(strVendorNameFilter = "", GridKnownFunction.NoFilter, GridKnownFunction.Contains)
 
        Dim colItemNumber = mtv.GetColumnSafe("ITEMNMBR")
        colItemNumber.CurrentFilterValue = strItemNumberFilter
        colItemNumber.CurrentFilterFunction = If(strItemNumberFilter = "", GridKnownFunction.NoFilter, GridKnownFunction.Contains)
 
        RadGrid1.Rebind()
 
    Catch ex As ThreadAbortException
    Catch ex As Exception
        ErrorHandler.globalErrorHandler(ex, strError, App.AppName, App.UserName, False)
        Me.lblError.Text = ex.Message
    End Try
 
End Sub

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences